General: This article focuses on how to access and maintain XML documents using XMLDOM, which is implemented by the Microsoft Parser xmldom.
The MSXML parser implements a number of useful methods that you can use to track the state of the incoming process when you are entering a large document. These methods are also useful for asynchronous incoming documents from the Internet.
To open a document on the Internet, you need to provide an absolute URL, and you must add the http://prefix. Here is an example.
Xdoc.async = False
If xdoc.load ("Http://www.develop.com/hp/brianr/cds.xml") Then
' The document was successfully transferred into
' Do what we like to do
Else
' Document failed to import
End If
Set the Async property to False so that the parser does not give control to your code until the document is entered. If you save Async as true, you must check the ReadyState property when accessing the document or use the DOMDocument event to prompt your code when the document is accessible.
You access the type of the node through the two properties implemented by the IXMLDOMNode interface. The NodeType property lists all Domnodetype items (some items are listed on the table above). Alternatively, you can use the nodeTypeString property to get a string representing the node type.
Once you have a DOM reference to the document, you can traverse the hierarchy of nodes. With a document reference, you can access the ChildNodes property, which gives a top-down directory containing all the nodes. The ChildNodes property implements the IXMLDOMNodeList, which supports the For/each structure of Visual Basic, so you can enumerate all the nodes in the childnodes. In addition, the ChildNodes property implements the Level property, which returns the number of all child nodes.
Not just the Document object has the ChildNodes property, each node has a ChildNodes property. Because of this, the ChildNodes property and IXMLDOMNode's HasChildNodes property mates make it very convenient for you to traverse documents, access elements, attributes, and values.
It is worth mentioning that there is a parent-child relationship between element and element values. For example, in the CDs XML document, Element <title> represents the name of the song, to know the value of <title>, you need to access the properties of the node Node_text. If you find a node with data that you are interested in, you can access its properties, or you can access its parent node through the ParentNode property.