VBS to extract attributes from all xml documents in a directory



I have the below VBS, which pulls out two attributes from one piece of xml, I would like to modify the code to look in the data directory and pull out these two attributes for all xml documents within in.


Would also be neat if it could put the output from each file on the same row.


Username - ID rather than the current


Username


ID



Set objXML2 = CreateObject("Microsoft.XMLDOM")
objXML2.async = "false"
strdir="c:\temp\XML\Data\test.xml"
If (Not objXML2.load(strdir)) Then
wscript.echo "Unable to load file '" & strdir & "'. "
WScript.Quit(1)
End If
Set colNodes1 = objXML2.selectNodes ("/User/Username")
For Each objNode in colNodes1
wscript.echo objnode.getAttribute("name")& " : " & objNode.text
NEXT
Set colNodes2 = objXML2.selectNodes ("/User/ID")
For Each objNode in colNodes2
wscript.echo objnode.getAttribute("name")& " : " & objNode.text

NEXT

No comments:

Post a Comment