When I used to introduce xml and try to use DOM, not only did one ask me if I could use DOM to directly generate an XML file out of thin air. When I used to introduce xml and try to use DOM, not only did one ask me if I could use DOM to directly generate an XML file out of thin air.
Of course, this is acceptable, followed by How to write programs.
In this article, we will use the DOM implementation of the COM interface of VB and MSXML as an example:
First of all, I want to explain that the MSXML version I use is IE5, and the version number is 5.0.2919.3800. the interfaces of earlier Microsoft versions are different from those of the new version, let's take a look at her interfaces and descriptions.
If you are not familiar with vb and COM, it may be difficult to look at the following. However, VB is simpler and clearer than other languages.
First, declare the variables of the following objects:
Dim tempdoc As MSXML.DOMDocumentDim 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
Generate the root node and set it as the root of the file
Set root = tempdoc.createElement("MyRoot") Set tempdoc.documentElement = root
Generate a child node and add it to the root node, and set an attribute for this node
Set tempnode = tempdoc.createNode(MSXML.NODE_ELEMENT, "MyNode", "") tempnode.Text = "MyNodeValue" root.appendChild tempnode
Get the element node interface and add attributes
Set tempelement = tempnode tempelement.setAttribute "MyAttribute", "MyAttributeValue"
Write xml files
Open "MyXMLFile.xml" for output as #1 PRint #1, root.XML Close #1
The content of the XML file generated by the above program is as follows:
MyNodeValue
In MSXML, non-DOM interfaces are also available, which depends on your usage.
The above is a detailed introduction to how to use DOM to create XML. For more information, see The PHP Chinese website (www.php1.cn )!