Dom|xml| created I used to introduce XML and let others try to use DOM, and more than one person asked me whether Dom can be used to generate an XML file directly from scratch.
Of course, this is certainly possible, followed by how to write the program.
So I'm going to talk about this as an example of the DOM implementation of VB and MSXML's COM interface in this article:
The first thing I would like to say is that the version of MSXML I use is IE5, the version number is 5.0.2919.3800, and Microsoft's earlier version of the interface is somewhat different from the new one, so when you're programming, you should look at her interface and instructions.
If you are not familiar with VB and COM, look at the following may be more laborious, but VB than other language implementation, should be relatively simple and clear.
First declare the variables for the following objects:
Dim Tempdoc as MSXML. DOMDocument
Dim Tempnode as MSXML. IXMLDOMNode
Dim tempelement as MSXML. IXMLDOMElement
Dim Tempattribute as MSXML. IXMLDOMElement
Dim Root as MSXML. IXMLDOMElement
Generate an XML DOMDocument object
Set Tempdoc = New MSXML. DOMDocument
To generate the root node and set it to the root of the file
Set root = Tempdoc.createelement ("Myroot")
Set tempdoc.documentelement = root
Build child node add to root node and set a property for this node
Set Tempnode = Tempdoc.createnode (MSXML. Node_element, "Mynode", "")
Tempnode. Text = "Mynodevalue"
Root.appendchild Tempnode
Gets the interface of the element node, adding attributes
Set tempelement = Tempnode
Tempelement.setattribute "MyAttribute", "Myattributevalue"
Write XML file
Open "Myxmlfile.xml" for output as #1
Print #1, Root. Xml
Close #1
The following is the contents of the XML file generated by the above program:
Mynodevalue
There are also non-dom interfaces available in MSXML, which depends on how you use them.
Author: Keep your/xml