2015-05-02 21 views
0

在此上下文中我加載XML文檔然後使用它的名稱和重新定位所述節點選擇節點的節點....但在下面的代碼其示出了錯誤 「'//文本框[@ NAME ='PlayerID_txt」具有無效令牌「。如何選擇從XML

XmlDocument nodeDoc = new XmlDocument(); 
      nodeDoc.Load(@"E:\Projects\Niyas\CompressorAndDecompressor\Reports\Reports\Reports\rdlcReport\PlayerSubReport1.rdlc"); 



      string itemId=""; 
      XmlNode node=null; 

      for (int i = 0; i < 6;i++) 
      { 

       if (dgvDesigngrid.Rows[i].Cells["Textbox_Id"].Value != null && dgvDesigngrid.Rows[i].Cells["Textbox_Id"].Value !="") 
       { 
        itemId = dgvDesigngrid.Rows[i].Cells["Name"].Value.ToString(); 



        node = nodeDoc.SelectSingleNode(string.Format("//Textbox[@Name='{0}'", itemId)); 
       } 



       // XmlNode node = nodeDoc.SelectSingleNode(string.Format("/root/node[@Textbox_Id = '{0}']", itemId)); 
       if (node != null) 
       { 
        node.ParentNode.AppendChild(node); 
       } 
      } 
     } 


    <?xml version="1.0" encoding="utf-8"?> 
<Report xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner" xmlns="http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition"> 
    <DataSources> 
    <DataSource Name="ReportsReportsDatasets"> 
     <ConnectionProperties> 
     <DataProvider>System.Data.DataSet</DataProvider> 
     <ConnectString>/* Local Connection */</ConnectString> 
     </ConnectionProperties> 
     <rd:DataSourceID>ae389da4-d5e0-4a2e-9a16-8b35e854428e</rd:DataSourceID> 
    </DataSource> 
    </DataSources> 
    <DataSets> 
    <DataSet Name="SubReportDetails"> 
     <Fields> 
     <Field Name="PlayerID"> 
      <DataField>PlayerID</DataField> 
      <rd:TypeName>System.String</rd:TypeName> 
     </Field> 
     <Field Name="PlayerName"> 
      <DataField>PlayerName</DataField> 
      <rd:TypeName>System.String</rd:TypeName> 
     </Field> 
     <Field Name="BelongsTo"> 
      <DataField>BelongsTo</DataField> 
      <rd:TypeName>System.String</rd:TypeName> 
     </Field> 
     </Fields> 
     <Query> 
     <DataSourceName>ReportsReportsDatasets</DataSourceName> 
     <CommandText>/* Local Query */</CommandText> 
     </Query> 
     <rd:DataSetInfo> 
     <rd:DataSetName>Reports.Reports.Datasets</rd:DataSetName> 
     <rd:TableName>PlayerMasterDetailsDataTable</rd:TableName> 
     <rd:ObjectDataSourceType>Reports.Reports.Datasets.Dataset+PlayerMasterDetailsDataTable, Reports.Datasets.Dataset.Designer.cs, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null</rd:ObjectDataSourceType> 
     </rd:DataSetInfo> 
    </DataSet> 
    </DataSets> 
    <Body> 
    <ReportItems> 
     <Tablix Name="Tablix1"> 
     <TablixBody> 
      <TablixColumns> 
      <TablixColumn> 
       <Width>0.98425in</Width> 
      </TablixColumn> 
      <TablixColumn> 
       <Width>0.98425in</Width> 
      </TablixColumn> 
      <TablixColumn> 
       <Width>0.98425in</Width> 
      </TablixColumn> 
      </TablixColumns> 
      <TablixRows> 
      <TablixRow> 
       <Height>0.23622in</Height> 
       <TablixCells> 
       <TablixCell> 
        <CellContents> 
        <Textbox Name="Textbox1"> 
         <CanGrow>true</CanGrow> 
         <KeepTogether>true</KeepTogether> 
         <Paragraphs> 
         <Paragraph> 
          <TextRuns> 
          <TextRun> 
           <Value>Player ID</Value> 
           <Style /> 
          </TextRun> 
          </TextRuns> 
          <Style /> 
         </Paragraph> 
         </Paragraphs> 
         <rd:DefaultName>Textbox1</rd:DefaultName> 
         <Style> 
         <Border> 
          <Color>LightGrey</Color> 
          <Style>Solid</Style> 
         </Border> 
         <PaddingLeft>2pt</PaddingLeft> 
         <PaddingRight>2pt</PaddingRight> 
         <PaddingTop>2pt</PaddingTop> 
         <PaddingBottom>2pt</PaddingBottom> 
         </Style> 
        </Textbox> 
        </CellContents> 
       </TablixCell> 
       <TablixCell> 
        <CellContents> 
        <Textbox Name="Textbox3"> 
         <CanGrow>true</CanGrow> 
         <KeepTogether>true</KeepTogether> 
         <Paragraphs> 
         <Paragraph> 
          <TextRuns> 
          <TextRun> 
           <Value>Player Name</Value> 
           <Style /> 
          </TextRun> 
          </TextRuns> 
          <Style /> 
         </Paragraph> 
         </Paragraphs> 
         <rd:DefaultName>Textbox3</rd:DefaultName> 
         <Style> 
         <Border> 
          <Color>LightGrey</Color> 
          <Style>Solid</Style> 
         </Border> 
         <PaddingLeft>2pt</PaddingLeft> 
         <PaddingRight>2pt</PaddingRight> 
         <PaddingTop>2pt</PaddingTop> 
         <PaddingBottom>2pt</PaddingBottom> 
         </Style> 
        </Textbox> 
        </CellContents> 
       </TablixCell> 
       <TablixCell> 
        <CellContents> 
        <Textbox Name="Textbox5"> 
         <CanGrow>true</CanGrow> 
         <KeepTogether>true</KeepTogether> 
         <Paragraphs> 
         <Paragraph> 
          <TextRuns> 
          <TextRun> 
           <Value>Belongs To</Value> 
           <Style /> 
          </TextRun> 
          </TextRuns> 
          <Style /> 
         </Paragraph> 
         </Paragraphs> 
         <rd:DefaultName>Textbox5</rd:DefaultName> 
         <Style> 
         <Border> 
          <Color>LightGrey</Color> 
          <Style>Solid</Style> 
         </Border> 
         <PaddingLeft>2pt</PaddingLeft> 
         <PaddingRight>2pt</PaddingRight> 
         <PaddingTop>2pt</PaddingTop> 
         <PaddingBottom>2pt</PaddingBottom> 
         </Style> 
        </Textbox> 
        </CellContents> 
       </TablixCell> 
       </TablixCells> 
      </TablixRow> 
      <TablixRow> 
       <Height>0.23622in</Height> 
       <TablixCells> 
       <TablixCell> 
        <CellContents> 
        <Textbox Name="PlayerID_txt"> 
         <CanGrow>true</CanGrow> 
         <KeepTogether>true</KeepTogether> 
         <Paragraphs> 
         <Paragraph> 
          <TextRuns> 
          <TextRun> 
           <Value>=Fields!PlayerID.Value</Value> 
           <Style /> 
          </TextRun> 
          </TextRuns> 
          <Style /> 
         </Paragraph> 
         </Paragraphs> 
         <Style> 
         <Border> 
          <Color>LightGrey</Color> 
          <Style>Solid</Style> 
         </Border> 
         <PaddingLeft>2pt</PaddingLeft> 
         <PaddingRight>2pt</PaddingRight> 
         <PaddingTop>2pt</PaddingTop> 
         <PaddingBottom>2pt</PaddingBottom> 
         </Style> 
        </Textbox> 
        <rd:Selected>true</rd:Selected> 
        </CellContents> 
       </TablixCell> 
       <TablixCell> 
        <CellContents> 
        <Textbox Name="PlayerName_txt"> 
         <CanGrow>true</CanGrow> 
         <KeepTogether>true</KeepTogether> 
         <Paragraphs> 
         <Paragraph> 
          <TextRuns> 
          <TextRun> 
           <Value>=Fields!PlayerName.Value</Value> 
           <Style /> 
          </TextRun> 
          </TextRuns> 
          <Style /> 
         </Paragraph> 
         </Paragraphs> 
         <Style> 
         <Border> 
          <Color>LightGrey</Color> 
          <Style>Solid</Style> 
         </Border> 
         <PaddingLeft>2pt</PaddingLeft> 
         <PaddingRight>2pt</PaddingRight> 
         <PaddingTop>2pt</PaddingTop> 
         <PaddingBottom>2pt</PaddingBottom> 
         </Style> 
        </Textbox> 
        </CellContents> 
       </TablixCell> 
       <TablixCell> 
        <CellContents> 
        <Textbox Name="BelongsTo_txt"> 
         <CanGrow>true</CanGrow> 
         <KeepTogether>true</KeepTogether> 
         <Paragraphs> 
         <Paragraph> 
          <TextRuns> 
          <TextRun> 
           <Value>=Fields!BelongsTo.Value</Value> 
           <Style /> 
          </TextRun> 
          </TextRuns> 
          <Style /> 
         </Paragraph> 
         </Paragraphs> 
         <Style> 
         <Border> 
          <Color>LightGrey</Color> 
          <Style>Solid</Style> 
         </Border> 
         <PaddingLeft>2pt</PaddingLeft> 
         <PaddingRight>2pt</PaddingRight> 
         <PaddingTop>2pt</PaddingTop> 
         <PaddingBottom>2pt</PaddingBottom> 
         </Style> 
        </Textbox> 
        </CellContents> 
       </TablixCell> 
       </TablixCells> 
      </TablixRow> 
      </TablixRows> 
     </TablixBody> 
     <TablixColumnHierarchy> 
      <TablixMembers> 
      <TablixMember /> 
      <TablixMember /> 
      <TablixMember /> 
      </TablixMembers> 
     </TablixColumnHierarchy> 
     <TablixRowHierarchy> 
      <TablixMembers> 
      <TablixMember> 
       <KeepWithGroup>After</KeepWithGroup> 
      </TablixMember> 
      <TablixMember> 
       <Group Name="Details" /> 
      </TablixMember> 
      </TablixMembers> 
     </TablixRowHierarchy> 
     <DataSetName>SubReportDetails</DataSetName> 
     <Top>3.0607cm</Top> 
     <Left>1.89653cm</Left> 
     <Height>1.2cm</Height> 
     <Width>7.5cm</Width> 
     <Style> 
      <Border> 
      <Style>None</Style> 
      </Border> 
     </Style> 
     </Tablix> 
    </ReportItems> 
    <Height>4.21875in</Height> 
    <Style /> 
    </Body> 
    <Width>6.5in</Width> 
    <Page> 
    <PageHeight>29.7cm</PageHeight> 
    <PageWidth>21cm</PageWidth> 
    <LeftMargin>2cm</LeftMargin> 
    <RightMargin>2cm</RightMargin> 
    <TopMargin>2cm</TopMargin> 
    <BottomMargin>2cm</BottomMargin> 
    <ColumnSpacing>0.13cm</ColumnSpacing> 
    <Style /> 
    </Page> 
    <rd:ReportID>75d0c901-26e2-4b62-9761-479cea86626e</rd:ReportID> 
    <rd:ReportUnitType>Cm</rd:ReportUnitType> 
</Report> 
+0

你的XML文件架構可能是查找問題 – Fabio

回答

1

node = nodeDoc.SelectSingleNode(string.Format("//Textbox[@Name='{0}'", itemId));

我認爲它缺少一個右]

+0

有幫助我糾正了....但它不是問題... – sams