How to Design XML Documents
Aug 27 2:51:29
Back online!
Jul 30 16:17:53
Response to "Knowledge Management 2.0"
Jul 18 2:45:52
Drupal Apps
Jun 3 7:17:00
Google Sites and the AJAX universe
May 21 1:18:39
I don't know if this would ever be useful to anyone, but anyway:
Option Explicit
Dim xmlDoc
Set xmlDoc = CreateObject("Microsoft.XMLDOM")
xmlDoc.async = False
xmlDoc.loadXML("<GetList><a><b attr=""5"">a node</b></a></GetList>")
DisplayNode xmlDoc.childNodes
' =================== Helper Routines ==================
Sub DisplayNode(Nodes)
DisplayNode_ Nodes, 0
End Sub
Sub DisplayNode_(Nodes, Indent)
Dim xNode
For Each xNode In Nodes
Select Case xNode.nodeType
Case 1: ' NODE_ELEMENT
If xNode.nodeName <> "#document" Then
' change DisplayAttrs_(xNode, Indent + 2) to
' DisplayAttrs_(xNode, 0) for inline attributes
WScript.Echo strDup(" ", Indent) & "<" & xNode.nodeName & _
DisplayAttrs_(xNode, Indent + 2) & ">"
If xNode.hasChildNodes Then
DisplayNode_ xNode.childNodes, Indent + 2
End If
WScript.Echo strDup(" ", Indent) & "</" & xNode.nodeName & ">"
Else
If xNode.hasChildNodes Then
DisplayNode_ xNode.childNodes, Indent + 2
End If
End If
Case 3: ' NODE_TEXT
WScript.Echo strDup(" ", Indent) & xNode.nodeValue
End Select
Next
End Sub
Function DisplayAttrs_(Node, Indent)
Dim xAttr, res
res = ""
For Each xAttr In Node.attributes
If Indent = 0 Then
res = res & " " & xAttr.name & "=""" & xAttr.value & """"
Else
res = res & vbCrLf & strDup(" ", Indent) & xAttr.name & _
"=""" & xAttr.value & """"
End If
Next
DisplayAttrs_ = res
End Function
Function strDup(dup, c)
Dim res, i
res = ""
For i = 1 To c
res = res & dup
Next
strDup = res
End Function