0

Having trouble reading a certain format of XML Nodes that's driving me and my partner nuts...

we've tried this.. but we keep getting "blank" msgboxs.. any help would be very well appreciated

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 FILE

 <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" />
2
  • 1
    Your XML (as far as I can see it) has no text, only attribute values. Commented Jul 29, 2013 at 19:42
  • ah makes sense. i'll tell the developer they have to change their XML output. thank you so much for this Commented Jul 29, 2013 at 19:44

1 Answer 1

2

Minimal demo code for dealing with attributes:

  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

output:

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

use this to lookup objects/functions/properties in the docs.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.