0

我有这个 xml 文件:

  <Item Text="Reports" Navigateurl ="Reports/Default.aspx" Select="true">
  <Group>
    <Item Text="Customers" NavigateUrl="Reports/Customers/Default.aspx" Select="true">
      <Group>
        <Item Text="Customers" NavigateUrl="Reports/Customers/CustomerList.aspx" 
            Select="true"   />
        <Item Text="Customer Products" 
         NavigateUrl="Reports/Customers/CustomersProducts.aspx" Select="true" />
        <Item Text="Customer Measurements" 
        NavigateUrl="Reports/Customers/CustomerLocationMeasurements.aspx" Select="true"  />
        <Item Text="Customer Groups" NavigateUrl="Reports/Customers/CustomerGroups.aspx" 
         Select="true"/>
        <Item Text="Customer Outages" NavigateUrl="Reports/Customers/CustomerOutages.aspx" 
         Select="true" />
      </Group>
    </Item>
    <Item Text="Rules" NavigateUrl="Reports/Rules/Default.aspx" Select="true" >
      <Group>
        <Item Text="Customer Product Rules" 
         NavigateUrl="Reports/Rules/CustomerProducts.aspx" Select="true"/>
        <Item Text="Customer Product Rules Event Limits" 
          NavigateUrl="Reports/Rules/CustomerProductEventLimits.aspx" Select="true" />
        <Item Text="Customer Product  Rules Curtailable Days/Hours" 
         NavigateUrl="Reports/Rules/CustomerProductCurtailableDaysHours.aspx" 
          Select="true"  />
      </Group>
    </Item>
     </Group>
  </Item>

所以,当我使用这个 XPATH 表达式时,

          XmlDataSource XmlDataSource1 = new XmlDataSource();
        XmlDataSource1.DataFile = "~/Menu.xml";
        XmlDataSource1.XPath = "//Item[@Text ='Reports']/Group/Item                  
                                  [@Select='true']       
        XmlDataSource1.DataBind();
        SiteMap1.DataSource = XmlDataSource1;

我得到这个输出:

         Customers
            Group
               Customer Pages
          Rules
             Group
               Rules Pages

但我不希望 Group 标签显示在输出中。你能告诉我这是如何实现的吗?

4

1 回答 1

1

XPath 是一种查询语言,用于从 XML 文档中选择节点或提取其他数据。因此它不能修改文档的结构——例如删除一个节点

这种处理——称为转换,可以很容易地用 XSLT 和(不那么容易)用 XQuery 完成。

于 2012-05-09T14:30:21.127 回答