Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法正确制定XPath语法以在complexe xml文件中搜索_Xml_Xpath - Fatal编程技术网

无法正确制定XPath语法以在complexe xml文件中搜索

无法正确制定XPath语法以在complexe xml文件中搜索,xml,xpath,Xml,Xpath,我在正确制定XPath以研究XML文件时遇到问题我是Visual Basic 2015,使用4.0 net framework,它位于excel模板中 这是xml文件的一部分 <Data ss:Type="String">1000102043</Data> </Cell> <Cell> <Data ss:Type="String"></Data> </Cell>

我在正确制定XPath以研究XML文件时遇到问题我是Visual Basic 2015,使用4.0 net framework,它位于excel模板中

这是xml文件的一部分

      <Data ss:Type="String">1000102043</Data>
    </Cell>
    <Cell>
      <Data ss:Type="String"></Data>
    </Cell>
    <Cell>
      <Data ss:Type="Number">1.0</Data>
    </Cell>
    <Cell>
      <Data ss:Type="String">Lot / Fourre-tout</Data>
    </Cell>
    <Cell ss:StyleID="Currency">
      <Data ss:Type="Number">320,38</Data>
    </Cell>
    <Cell ss:StyleID="Currency">
      <Data ss:Type="Number">320,38</Data>
    </Cell>
    <Cell>
      <Data ss:Type="String">CAD</Data>
    </Cell>
    <Cell>
      <Data ss:Type="Number">1.0</Data>
    </Cell>
    <Cell>
      <Data ss:Type="String">each / par pi&#232;ce</Data>
    </Cell>
    <Cell ss:StyleID="Currency">
      <Data ss:Type="Number">0,51</Data>
    </Cell>
    <Cell ss:StyleID="Currency">
      <Data ss:Type="Number">1,02</Data>
    </Cell>
    <Cell>
      <Data ss:Type="String">CAD</Data>
    </Cell>
    <Cell>
      <Data ss:Type="Number">0.0</Data>
这是可行的,但我只需要数字行

我试过这个

xmlNodePrice = xmlDoc.GetElementsByTagName("//Data(@Type='Number')")
还有这个

xmlNodePrice = xmlDoc.GetElementsByTagName("//Data[@Type='Number''")
还是不行

这将调用
GetElementsByTagName()
,并按照其名称执行:它接受标记名并选择与标记名匹配的元素


如果您想使用XPath,可以使用and,它接受整个XPath,而不仅仅是标记名作为第一个参数。重载(带有第二个参数)可以采用命名空间管理器。有关更多信息和示例,请参见上面的和两个链接。

谢谢您的回答。它指引了我正确的方向,但我还有很多工作要做,以找出其余的问题

这是我的最终代码

    Public strPathFile As String
    Dim xmlDoc As New XmlDocument
    Dim xmlNode As XmlNodeList
    Dim nsMgr As XmlNamespaceManager
    Dim selectedNodes As XmlNodeList

    xmlDoc.Load(strPathFile)

    nsMgr = New XmlNamespaceManager(xmlDoc.NameTable)
    nsMgr.AddNamespace("o", "urn:schemas-microsoft-com:office:office")
    nsMgr.AddNamespace("x", "urn:schemas-microsoft-com:office:excel")
    nsMgr.AddNamespace("html", "http://www.w3.org/TR/REC-html40")
    nsMgr.AddNamespace("ss", "urn:schemas-microsoft-com:office:spreadsheet")

    selectedNodes = xmlDoc.SelectNodes("/ss:Workbook/ss:Worksheet/ss:Table/ss:Row/ss:Cell/ss:Data[@ss:Type=""Number""]", nsMgr)
    For Each selectedNode As XmlNode In selectedNodes
        'Do whatever
        End If
    Next
这是xml文件

      <Data ss:Type="String">1000102043</Data>
    </Cell>
    <Cell>
      <Data ss:Type="String"></Data>
    </Cell>
    <Cell>
      <Data ss:Type="Number">1.0</Data>
    </Cell>
    <Cell>
      <Data ss:Type="String">Lot / Fourre-tout</Data>
    </Cell>
    <Cell ss:StyleID="Currency">
      <Data ss:Type="Number">320,38</Data>
    </Cell>
    <Cell ss:StyleID="Currency">
      <Data ss:Type="Number">320,38</Data>
    </Cell>
    <Cell>
      <Data ss:Type="String">CAD</Data>
    </Cell>
    <Cell>
      <Data ss:Type="Number">1.0</Data>
    </Cell>
    <Cell>
      <Data ss:Type="String">each / par pi&#232;ce</Data>
    </Cell>
    <Cell ss:StyleID="Currency">
      <Data ss:Type="Number">0,51</Data>
    </Cell>
    <Cell ss:StyleID="Currency">
      <Data ss:Type="Number">1,02</Data>
    </Cell>
    <Cell>
      <Data ss:Type="String">CAD</Data>
    </Cell>
    <Cell>
      <Data ss:Type="Number">0.0</Data>

每个/PAR PI和α232;总工程师
0,51
1,02
计算机辅助设计
0
GetElementsByTagName()
听起来像是使用标记名(元素名),而不是完整的XPath表达式。有关如何使用XPath表达式选择节点的信息,请参见。