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
Xml 如何按祖先、父节点和子节点查找更复杂的特定节点_Xml_Xpath_Vbscript_Nodes - Fatal编程技术网

Xml 如何按祖先、父节点和子节点查找更复杂的特定节点

Xml 如何按祖先、父节点和子节点查找更复杂的特定节点,xml,xpath,vbscript,nodes,Xml,Xpath,Vbscript,Nodes,这是我的XML文件的精简版本simple.XML <Genealogy> <grandParent> <name>bob</name> <surname>Carter</surname> <Parent> <tel_Number>0033689765498</tel_Number> <mobile_Phone>2<

这是我的XML文件的精简版本
simple.XML

<Genealogy> 
  <grandParent> 
    <name>bob</name> 
    <surname>Carter</surname>
    <Parent>
      <tel_Number>0033689765498</tel_Number> 
      <mobile_Phone>2</mobile_Phone>
    </Parent>
  </grandParent>
  <grandParent> 
     <name>jean</name> 
     <surname>Wright</surname>
     <Parent>
      <tel_Number>0033648245432</tel_Number> 
      <mobile_Phone>1</mobile_Phone>
     </Parent>
  </grandParent>
</Genealogy>

请尝试以下XPath表达式:

//grandParent/Parent/tel_Number[text()='0033648245434' and ../../name/text()='jean']
name  = "jean"
phone = "0033648245434"

Set xml = CreateObject("Msxml2.DOMDocument.6.0")
xml.async = False
xml.load "C:\path\to\simple.xml"

expr = "//grandParent/Parent/tel_Number[text()='" & phone _
       & "' and ../../name/text()='" & name & "']"

Set nodes = xml.selectNodes(expr)

For n In nodes
  WScript.Echo n.parentNode.nodeName
Next
代码如下:

//grandParent/Parent/tel_Number[text()='0033648245434' and ../../name/text()='jean']
name  = "jean"
phone = "0033648245434"

Set xml = CreateObject("Msxml2.DOMDocument.6.0")
xml.async = False
xml.load "C:\path\to\simple.xml"

expr = "//grandParent/Parent/tel_Number[text()='" & phone _
       & "' and ../../name/text()='" & name & "']"

Set nodes = xml.selectNodes(expr)

For n In nodes
  WScript.Echo n.parentNode.nodeName
Next