0

无法读取某种格式的 XML 节点,这让我和我的伙伴发疯了……

我们已经尝试过了..但我们不断收到“空白”消息框..任何帮助将不胜感激

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

文件

 <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" />
4

1 回答 1

2

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

  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

输出:

==============
ban found
name: Elise
==============

使用它在文档中查找对象/函数/属性。

于 2013-07-29T20:00:10.790 回答