帮助XPath语法

时间:2011-06-27 14:32:24

标签: xml xpath sharepoint-2010 infopath

我正在尝试将NewDataset下的所有节点都放在所有'Items'节点上。能帮忙吗?

这是我的xml和Xpath语法。

string xpath = "/dfs:myFields/dfs:dataFields/GetItemsResponse/getItemsResult/NewDataset";
XPathNodeIterator clItems = this.DataSources[listDS.GetItems].CreateNavigator().Select(xpath, NamespaceManager);

XML:

<dfs:myFields
  xmlns:dfs="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution"
  xmlns:ns3="http://test222.com/"
  xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2010-11-22T16:05:55"
  xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
>
  <dfs:queryFields>
    <ns3:GetItems>
      <ns3:list1>test</ns3:list1>
    </ns3:GetItems>
  </dfs:queryFields>
  <dfs:dataFields>
    <GetItemsResponse xmlns="http://test222.com/">
      <GetItemsResult>
        <NewDataSet xmlns="">
          <Items>
            <Clist>list1</Clist>
            <Title>test1</Title>
           </Items>
           <Items>
              <Clist>list2</Clist>
              <Title>test2</Title>
           </Items>
        </NewDataSet>
      </GetItemsResult>
    </GetItemsResponse>
  </dfs:dataFields>
</dfs:myFields>

2 个答案:

答案 0 :(得分:1)

这应该是它:

//NewDataSet/Items

它返回所有项目。 在你的情况下,应该是

 string xpath = "//NewDataSet/Items";

答案 1 :(得分:0)

您忘记将名称空间(http://test222.com/)设置为GetItemsResponseGetItemsResult

完全合格:/dfs:myFields/dfs:dataFields/ns3:GetItemsResponse/ns3:GetItemsResult/NewDataSet/Items