VBScript XML Childnode looping

Author Message
TheQuestor

  • Total Posts : 5
  • Scores: 0
  • Reward points : 0
  • Joined: 1/18/2011
  • Status: offline
VBScript XML Childnode looping Friday, July 15, 2011 11:03 PM (permalink)
0
I'm going crazy. I can't figure out how to loop through child nodes of this sample xml
 [addons.xml] 
<?xml version="1.0" encoding="UTF-8"?>
<addons>
<addon id="script.game.tic.tac.toe" name="Tic Tac Toe" version="1.0.2" provider-name="Frost (passion-xbmc.org)">
  <requires>
    <import addon="xbmc.python" version="1.0"/>
  </requires>
  <extension point="xbmc.python.script" library="default.py"/>
  <extension point="xbmc.addon.metadata">
    <platform>all</platform>
    <nochangelog>true</nochangelog>
    <summary>Tic Tac Toe for XBMC</summary>
    <description>Jeu du Tic Tac Toe ou dit aussi Morpion. Jouer contre XBMC ou avec un deuxième joueur.</description>
  </extension>
</addon>
<addon id="script.game.snake" name="Snake" version="1.0.2" date="11.10.2010" provider-name="Rocko aka Rockstar">
  <requires>
    <import addon="xbmc.python" version="1.0"/>
  </requires>
  <extension point="xbmc.python.script" library="default.py"/>
  <extension point="xbmc.addon.metadata">
    <platform>all</platform>
    <summary>Snake Game for XBMC</summary>
    <description>All credits and special thanks to Rocko.</description>
    <disclaimer>Remember, High-scores on-line not working....</disclaimer>
  </extension>
</addon>
<addon id="script.module.dialogaddonscan" name="Dialog Addon Scan" version="1.0.7" date="16.12.2010" provider-name="Frost (passion-xbmc.org)">
  <requires>
    <import addon="xbmc.python" version="1.0"/>
  </requires>
  <extension point="xbmc.python.module" library="lib"/>
  <extension point="xbmc.addon.metadata">
    <summary>Dialog Scan for Add-on</summary>
    <description>Dialog Scan for Add-on</description>
    <license>GPL</license>
    <platform>all</platform>
    <nofanart>true</nofanart>
    <noicon>true</noicon>
  </extension>
</addon>
</addons>

 
The following code reads it but only returns the 1st entry
[test.vb]
SET xmlDoc=CreateObject("Msxml2.DOMDocument.3.0")
xmlDoc.async="false"
xmlDoc.load("test.xml")
If xmlDoc.parseError.errorCode <> 0 Then
 wscript.Echo xmlDoc.parseError.errorCode
 wscript.Echo xmlDoc.parseError.reason
 wscript.Echo xmlDoc.parseError.line
End If
Set AValue=xmlDoc.documentElement.selectSingleNode("addon")
valueA = AValue.getAttribute("id")
valueB = AValue.getAttribute("version")
WScript.Echo valueA
WScript.Echo valueB
WScript.Echo "---------------------------"

 
The following looks like it should loop but I can't get it to return anything :(
[test2.vb]
 
set objXML = CreateObject("Msxml2.DOMDocument.3.0")
objXML.async = false
objXML.load("addons.xml")
If objXML.parseError.errorCode <> 0 Then
 wscript.Echo objXML.parseError.errorCode
 wscript.Echo objXML.parseError.reason
 wscript.Echo objXML.parseError.line
End If
Set objNodeList = objXML.selectNodes("addon")
For each objSingleNode in objNodeList
wscript.Echo objSingleNode.selectSingleNode("id")
wscript.Echo objSingleNode.selectSingleNode("version")
Next

 
I get no error just nothing :(
 
can somebody in really simple language help me figure this out?
 
TIA
 
 
#1
    ehvbs

    • Total Posts : 3321
    • Scores: 110
    • Reward points : 0
    • Joined: 6/22/2005
    • Location: Germany
    • Status: offline
    Re:VBScript XML Childnode looping Sunday, July 17, 2011 9:51 PM (permalink)
    0
    An XPath query starts in the current context; so it makes a difference if you search for "addon" in xmlDoc or  .xmlDoc.documentElement. By looking for "/addons/addon" or "//addon" you can compensate for that.
     
    Code to experiment with:
    Dim sFSpec : sFSpec     = goFS.GetAbsolutePathName( "..\testdata\xml\addons.xml" ) 
    Dim objXML : Set objXML = CreateObject("Msxml2.DOMDocument.3.0")
    objXML.async = False
    objXML.setProperty "SelectionLanguage", "XPath"
    If Not objXML.load( sFSpec ) Then
    WScript.Echo objXML.parseError.errorCode
    WScript.Echo objXML.parseError.reason
    WScript.Echo objXML.parseError.line
    Else
    Dim sFind         : sFind             = "/addons/addon" ' "addon" ' "/addons/addon" ' "//addon" '
    '    Dim objSingleNode : Set objSingleNode = objXML.documentElement.selectSingleNode( sFind )
    Dim objSingleNode : Set objSingleNode = objXML.selectSingleNode( sFind )
    If objSingleNode Is Nothing Then
    WScript.Echo "can't find any", sFind, "node."
    Else
    WScript.Echo "got the first", sFind, "node."
    WScript.Echo objSingleNode.getAttribute("id")
    WScript.Echo objSingleNode.getAttribute("version")
    End If
    '    Dim objNodeList : Set objNodeList = objXML.documentElement.selectNodes( sFind )
    Dim objNodeList : Set objNodeList = objXML.selectNodes( sFind )
    If 0 = objNodeList.length Then
    WScript.Echo "can't find any", sFind, "nodes."
    Else
    WScript.Echo "found", objNodeList.length, sFind, "nodes."
    For Each objSingleNode in objNodeList
    WScript.Echo objSingleNode.getAttribute("id")
    WScript.Echo objSingleNode.getAttribute("version")
    Next
    End If
    End If
    (pay attention to the the replacement of your objSingleNode.selectSingleNode("id"))
     
    #2

      Online Bookmarks Sharing: Share/Bookmark

      Jump to:

      Current active users

      There are 0 members and 1 guests.

      Icon Legend and Permission

      • New Messages
      • No New Messages
      • Hot Topic w/ New Messages
      • Hot Topic w/o New Messages
      • Locked w/ New Messages
      • Locked w/o New Messages
      • Read Message
      • Post New Thread
      • Reply to message
      • Post New Poll
      • Submit Vote
      • Post reward post
      • Delete my own posts
      • Delete my own threads
      • Rate post

      2000-2012 ASPPlayground.NET Forum Version 3.9