Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.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/2/visual-studio-2010/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
VB脚本-在一行中读取多个XML节点?_Xml_Visual Studio 2010_Visual Studio_Vbscript - Fatal编程技术网

VB脚本-在一行中读取多个XML节点?

VB脚本-在一行中读取多个XML节点?,xml,visual-studio-2010,visual-studio,vbscript,Xml,Visual Studio 2010,Visual Studio,Vbscript,在读取某种格式的XML节点时遇到困难,这会让我和我的合作伙伴发疯 我们已经试过了。。但我们不断收到“空白”MSGBox。。任何帮助都将不胜感激 Set xmlObject = CreateObject("Msxml2.DOMDocument.6.0") urlPath = "C:\Users\...\Desktop\LolChampsSelect.xml" xmlObject.async = False xmlObject.load urlPath 'set ban = xmlObject.

在读取某种格式的XML节点时遇到困难,这会让我和我的合作伙伴发疯

我们已经试过了。。但我们不断收到“空白”MSGBox。。任何帮助都将不胜感激

Set xmlObject = CreateObject("Msxml2.DOMDocument.6.0")
urlPath = "C:\Users\...\Desktop\LolChampsSelect.xml"

xmlObject.async = False
xmlObject.load urlPath

'set ban = xmlObject.selectNodes("//*")
set ban = xmlObject.selectNodes("//*")
set ban = xmlObject.selectNodes("//red/ban[@order]
msgbox ban(0).text
XML文件

 <championSelect>
       <blue>
         <ban order="1" name="Darius"/>
         <ban order="3" name="Elise" />
         <ban order="5" name="Twisted Fate" />
         <pick order="1" name="Gragas" />
         <pick order="4" name="Shen" />
         <pick order="5" name="Shyvanna" />

处理属性的最小演示代码:

  Dim sXml : sXml = Join(Array(_
        "<championSelect>" _
      , " <blue>" _
      , "  <ban order=""1"" name=""Darius""/>" _
      , "  <ban order=""3"" name=""Elise"" />" _
      , " </blue>" _
      , "</championSelect>" _
  ), vbCrLf)
  Dim objMSXML : Set objMSXML = CreateObject("Msxml2.DOMDocument")
  objMSXML.setProperty "SelectionLanguage", "XPath"
  objMSXML.async = False
  objMSXML.loadXml sXml

  If 0 = objMSXML.parseError Then
     Dim ndFound : Set ndFound = objMSXML.SelectSingleNode("/championSelect/blue/ban[@order=""3""]")
     WScript.Echo ndFound.tagName, "found"
     WScript.Echo "name:", ndFound.getAttribute("name")
  Else
     WScript.Echo objMSXML.parseError.reason
  End If

使用此选项可以查找文档中的对象/函数/属性。

您的XML(据我所知)没有文本,只有属性值。ah有意义。我会告诉开发人员他们必须更改XML输出。非常感谢你这么做哦,哇,谢谢你这么做,我会试试的!多谢各位
==============
ban found
name: Elise
==============