Re: cycle through xml tree using vbscript.
- From: "ekkehard.horner" <ekkehard.horner@xxxxxxxx>
- Date: Fri, 01 Feb 2008 23:13:26 +0100
Kim Oppalfens [MVP] > schrieb:
Does anyone have some code available to read through an entire xml tree and output the different elements to screen?I hope this
I am looking for some vbscript code to do this, not asp but real vbscript.
Dim oFS : Set oFS = CreateObject( "Scripting.FileSystemObject" )
Dim sFSpec : sFSpec = ".\soap00.xml"
Dim oXDoc : Set oXDoc = CreateObject( "Msxml2.DOMDocument" )
oXDoc.async = False
oXDoc.Load oFS.GetAbsolutePathName( sFSpec )
If 0 <> oXDoc.ParseError Then
WScript.Echo oXDoc.ParseError.Reason
Else
dumpXML_ 0, oXDoc.documentElement
End If
WScript.Quit 0
Sub dumpXML_( nIndent, oNode )
Const NODE_ATTRIBUTE = 2 ' 00000002
Const NODE_CDATA_SECTION = 4 ' 00000004
Const NODE_COMMENT = 8 ' 00000008
Const NODE_DOCUMENT = 9 ' 00000009
Const NODE_DOCUMENT_FRAGMENT = 11 ' 0000000B
Const NODE_DOCUMENT_TYPE = 10 ' 0000000A
Const NODE_ELEMENT = 1 ' 00000001
Const NODE_ENTITY = 6 ' 00000006
Const NODE_ENTITY_REFERENCE = 5 ' 00000005
Const NODE_INVALID = 0 ' 00000000
Const NODE_NOTATION = 12 ' 0000000C
Const NODE_PROCESSING_INSTRUCTION = 7 ' 00000007
Const NODE_TEXT = 3 ' 00000003
Select Case oNode.nodeType
Case NODE_ELEMENT
WScript.Echo String( nIndent, " " ), oNode.tagName
Dim oAttr
For Each oAttr In oNode.attributes
WScript.Echo String( nIndent, " " ), oAttr.Name, oAttr.Value
Next
Dim oChild
For Each oChild In oNode.childNodes
dumpXML_ nIndent + 2, oChild
Next
Case NODE_TEXT
WScript.Echo String( nIndent + 1, " " ), oneLine( oNode.text, 90 )
Case Else
WScript.Echo String( nIndent, " " ), "Ignored:", oNode.nodeType
End Select
End Sub
Function oneLine( sText, nMxLen )
Dim oRE : Set oRE = New RegExp
oRE.Global = True
oRE.Pattern = "(?:^\s+)|(?:\s+$)"
oneLine = oRE.Replace( sText, "" )
oRE.Pattern = "\s+"
oneLine = oRE.Replace( oneLine, " " )
If 0 < nMxLen Then
If nMxLen < Len( oneLine ) Then
oneLine = Left( oneline, nMxLen ) + " ..."
End If
End If
End Function
will get you started.
.
- References:
- cycle through xml tree using vbscript.
- From: Kim Oppalfens [MVP]
- cycle through xml tree using vbscript.
- Prev by Date: Re: Help needed... VBScript to determine ALL pst files from users profile
- Next by Date: Re: Tweak to VB Script
- Previous by thread: cycle through xml tree using vbscript.
- Next by thread: Re: some further comments...
- Index(es):