Public Sub LoadDocument()
Dim xdoc As DOMDocument30
Dim xmlDoc As String
xmlDoc = "Yourpath\MyPc.xml"
Set xdoc = New DOMDocument30
xdoc.validateOnParse = False
If xdoc.Load(xmlDoc) Then
' The document loaded successfully.
' Now do something intersting.
DisplayNode xdoc.childNodes, 0, xdoc
Else
' The document failed to load.
Dim strErrText As String
Dim xPE As MSXML2.IXMLDOMParseError
' Obtain the ParseError object
Set xPE = xdoc.parseError
With xPE
strErrText = "Your XML Document failed to load" & _
"due the following error." & vbCrLf & _
"Error #: " & .errorCode & ": " & xPE.reason & _
"Line #: " & .Line & vbCrLf & _
"Line Position: " & .linepos & vbCrLf & _
"Position In File: " & .filepos & vbCrLf & _
"Source Text: " & .srcText & vbCrLf & _
"Document URL: " & .url
End With
MsgBox strErrText, vbExclamation
End If
Set xPE = Nothing
End Sub
Public Sub DisplayNode(ByRef Nodes As MSXML2.IXMLDOMNodeList, _
ByVal Indent As Integer, xdoc As DOMDocument30)
Dim xNode As IXMLDOMNode
Dim oNode As IXMLDOMNode
Dim xattr As IXMLDOMAttribute
Dim xattr1 As IXMLDOMAttribute
Dim xElem As IXMLDOMElement
Dim strSQL As String
Dim strSQL1 As String
Indent = Indent + 1
On Error Resume Next
For Each xNode In Nodes
Debug.Print Space$(Indent) & xNode.parentNode.nodeName & _
":" & xNode.nodeValue & ":" & xNode.nodeTypedValue & _
":" & xNode.nodeType & ":";
For Each xattr In xNode.parentNode.Attributes
strSQL1 = strSQL1 & ": " & xattr.BaseName
strSQL = strSQL & ": " & xattr.Value
Next xattr
For Each xattr1 In xNode.Attributes
strSQL1 = strSQL1 & ": " & xattr1.BaseName
strSQL = strSQL & ": " & xattr1.Value
Next xattr1
If xNode.hasChildNodes Then
DisplayNode xNode.childNodes, Indent, xdoc
End If
Next xNode
End Sub