"Use the appendChild Method of the XMLDOM Object to add the objRoot "Element Reference to the XML Document.
objDom.appendChild objRoot
"Now, following the same steps, you will create references to the "child elements for the XML Document. The only difference is, when the "child elements are appended to the document, you will call the "appendChild Method of the IXMLDOMElement Object rather than the "appendChild Method of the XMLDOM Object. By using the IXMLDOMElement "to append the children, you are differentiating (and applying tiered "structure to) the child elements from the root element.
Set objChild1 = objDom.createElement("childElement1") objRoot.appendChild objChild1 Set objChild1 = objDom.createElement("childElement2") objRoot.appendChild objChild2
"The final step to take care of before saving this document is to add "an XML processing instruction. This is necessary so that XML parsers "will recognize this document as an XML document.
Set objPI = objDom.createProcessingInstruction("xml","vertsion="1.0"")
"Call the insertBefore Method of the XMLDOM Object in order to insert "the processing instruction before the root element (the zero element "in the XMLDOM childNodes Collection).
objDom.insertBefore objPI, objDom.childNodes(0)
"Calling the Save Method of the XMLDOM Object will save this XML "document to your disk drive. In this case, the document will be saved "to the "c:" drive and will be named "MyXMLDoc.xml". When saving an "XML document, if the file does not exist, it will be created. If it "does exist, it will be overwritten.
在"MyXMLDoc.xml"文档中,childElement1 和 childElement2 会以空的elements形式出现。如果它们被赋值,那么每个值都将由标记符括起来。 现在,让我们来思考一下如何将HTML数据写到XML文档中去。我们已经知道该如何创建和存储XML文档。将一个表单数据写到XML文档中去的过程,现在已演变成为Request Object"s Form Collection以及将每一个表单域的value书定到XML element value 中去的步骤重复。以上可以通过ASP来完成。 例:将数据输送到XML 现在,我们举一个普通的HTML表单的例子来说明。此Form有用户名,地址,电话,以及E-MAIL等几个域。并将这些信息写入XML文件中并保存。
<% ’-------------------------------------------------------------------- ’The "ConvertFormtoXML" Function accepts to parameters. ’strXMLFilePath - The physical path where the XML file will be saved. ’strFileName - The name of the XML file that will be saved. ’---------------------------------------------------------