XML document lesen und NodePfad und Wert ausgeben

Star InactiveStar InactiveStar InactiveStar InactiveStar Inactive
 
 '<!--********************************************************************
'*
'* File: XMLDocOutput.vbs
'* Author: Frank Wenzel
'* Created: 29.04.2010
'* Version: 1.00
'* Modified: 00.00.0000
'*
'* Description: Liest ein XML Dokument ein, gibt den Node Pfad
'* und den Wert Semikolon getrennt aus.
'*
'* needed: WSH 5.6
'*
'* note: Modified script from MSDN
'* Source: http://msdn.microsoft.com/en-us/library/ms755628(VS.85).aspx
'*
'********************************************************************-->
Option Explicit
Dim root, xmlDoc, child, indent, count, xmlFile, strPath
xmlFile = "D:\Script\GPOs\Server-GDC-WSUS-ICON-OFF.xml"
count = 0
indent=0
ReDim arrPath(0)
Set xmlDoc = createXmlDomDocument(xmlDoc)
xmlDoc.async = False
xmlDoc.validateOnParse=False
xmlDoc.load xmlFile
If xmlDoc.parseError.errorcode = 0 Then
'Walk from the root to each of its child nodes:
treeWalk(xmlDoc)
Else
WScript.Echo "There was an error in : " & xmlFile &"Line: " & _
xmlDoc.parseError.line & _
"Column: " & xmlDoc.parseError.linepos
End If
Function createXmlDomDocument(xd)
On Error Resume Next
'Uncomment the following line to use MSXML 3.0
Set xd = CreateObject("MSXML2.DOMDocument.3.0")
'Uncomment the following line to use MSXML 6.0
'Set xd = CreateObject("MSXML2.DOMDocument.6.0")
If (IsObject(xd) = False) Then
WScript.Echo "DOM document not created. Check MSXML version used in createXmlDomDocument."
Else
Set createXmlDomDocument = xd
'WScript.Echo "DOM document created."
End If
End Function
Function attributeWalk(node)
Dim i, attrib
For i=1 to indent
'WScript.Echo " "
Next
For Each attrib In node.attributes
WScript.Echo "|--"
WScript.Echo attrib.nodeTypeString
WScript.Echo ":"
WScript.Echo attrib.name
WScript.Echo "--"
WScript.Echo attrib.nodeValue
'WScript.Echo "<br />"
Next
End Function
Function treeWalk(node)
Dim nodeName, x
indent = indent +2
For Each child In node.childNodes
If child.nodeType < 3 Then
ReDim Preserve arrPath(count)
arrPath(count) = child.nodename
For x = 0 To UBound(arrPath)
strPath = strPath & arrPath(x) & "\"
Next
End If
' If (child.nodeType=1) Then
' If (child.attributes.length>0) Then
' indent=indent+2
' attributeWalk(child)
' indent=indent-2
' End If
' End If
If (child.hasChildNodes) Then
count = count +1
strPath = ""
treeWalk(child)
Else
For x = 0 To UBound(arrPath)
strPath = strPath & "\" & arrPath(x)
Next
WScript.Echo strPath & ";" & child.text
'WScript.Echo "-> " & child.parentNode.nodeName & ": " & child.text
strPath = ""
End If
Next
indent = indent-2
count = count -1
End Function