Store HTML form data in XML format (1)

Source: Internet
Author: User
Tags add format object html form processing instruction
xml| data

XML and HTML4. 0, please read the following example

Save form data in XML format

Typically, data submitted by a form in an ASP is typically written to the database. However, if you want to make it easier to send data, you can write it as an XML file format. This approach is more useful for data collected on the Web. Because XML is very simple for the platform you use, you don't need to convert the data format.

To write the submitted data as an XML document, you need to create a new XML document from Microsoft Xmldom object. Microsoft Xmldom object has a library of extensible objects that enables you to create elements,attributes and values that can be made into an XML document by creating these items. I can't make a complete presentation of the entire target model because it contains too much content, and for the site to be built, the target model can even form a relatively complete part of itself.

After Xmldom object is created, the structure of the XML is demonstrated by creating a goal, which is about the elements that makes up each layer of the XML document. Next, give an example of how XMLDOM was created. After you create the root element, attach it to the xmldom file. The child elements is then created and appended to the root element, and the document is finally stored.

Demo Microsoft Xmldom objects

<%

Dim Objdom
Dim Objroot
Dim ObjChild1
Dim ObjChild2
Dim OBJPI

The Xmldom object is created using the CreateObject method of the Server object
Set objdom = Server.CreateObject ("Microsoft.XMLDOM")
"Creates a IXMLDOMElement object using the Xmldom Createelemnet method.
The Createelemnet method has another string parameter, which represents the name of the element.
The return value is passed to the Objroot variable. Objroot represents the root element of an XML document ...

Set objroot = objdom.createelement ("RootElement")

"Use the AppendChild method of the XMLDOM Object to add the Objroot
The Element Reference to the XML Document.

Objdom.appendchild Objroot

"Now, following the same steps, you'll create references to the
"Child elements for the XML Document." The only difference are, when the
"Child elements are appended to the document, you'll call the
"AppendChild method of the IXMLDOMElement Object rather than the
"AppendChild method of the Xmldom Object. By using the IXMLDOMElement
"To append the Chi en, your are differentiating (and applying tiered
"Structure to" is 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 are to add
"An XML processing instruction." This is necessary the XML parsers
"Would recognize this document as an XML document."

Set OBJPI = objdom.createprocessinginstruction ("xml", "vertsion=" 1.0 "")

"Call the InsertBefore method of the ' xmldom Object in ' 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 would save this XML
"Document to your disk drive. In this case, the document would be saved
"To the" C: "Drive and would be named" Myxmldoc.xml ". When saving an
"XML document, if the file does not exist, it'll be created." If it
"Does exist, it'll be overwritten.

Objdom.save "C:\MyXMLDoc.xml"

%>



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.