Generating XML using the XML DOM (1)

Source: Internet
Author: User
Tags object object model
dom|xml| generate XML <--Editor's note: With the deepening of the application of XML in network development, the complexity of the language is increasing, and you can see this in the introduction to XML DOM of the new Object library XML-->

As you can see, XML is a powerful new data structure that allows you to separate the content and presentation of a Web page. However, at present, most of our articles only introduce the method of directly generating XML tags. Most of the time, we write the necessary tags and data manually.

Fortunately, Microsoft has provided the XML DOM (XML Document Object model), which is another way to write XML code. This object library allows you to build XML syntax trees and provides a more efficient way to create XML documents. For example, you can use the XML DOM to collect data from different locations or to create XML documents based on different kinds of data sources. In this article, we will describe the capabilities of several types of libraries and demonstrate how to use them in ASP.

Understanding the XML Document Object model
The XML DOM contains four main objects: XMLDOMDocument, Xmldomnode,xmldomnodelist, and Xmldomnamednodemap. As with any other object model, each XML DOM object has its own characteristics and methods. In this article, we will mainly introduce XMLDOMDocument and XMLDOMNode objects.

XMLDOMDocument objects
The XMLDOMDocument object represents the top-level node in the XML DOM hierarchy (do not confuse the root node in the XML document). It is the basis for building and manipulating XML structures. To create a XMLDOMDocument object variable, use the following CreateObject command:

Set objXMLDoc = _

CreateObject ("Microsoft.XMLDOM")

Table A: Lists some of the features and methods that we can get after XMLDOMDocument objects have been created.

Method description
CreateAttribute
Create a new property

Createcdatasection
Create a data Part node

Createcomment
Creating annotation Nodes

CreateElement
Create an element node with the specified name

Createentityreference
To create an entity reference object

CreateNode
Create a Node

createTextNode
Create a text node

Load
Loading an existing XML document

Save
Save XML document

Attribute description
PreserveWhitespace
Indicates whether to display spaces in an XML document T

Resolveexternals
Resolving name domains, DTDs, and external entity indexes

Validateonparse
Indicates whether the parser checks the document for legality

DocumentElement
Returns the root node of an XML document




Set Run options
As you can see in table A, you create a single XML node only if you create a XMLDOMDocument object. Before you do this, you can also set the parsing run condition of the XML document, which is useful if you are going to generate XML documents directly to the browser.

The Run option allows you to set up asynchronous downloads, provide document legality checking and retention spaces, and parse external indexes. To prevent asynchronous downloads, you can set the Asynch attribute to False. If you intend to replace a space with a new line of characters, you can set the PreserveWhitespace attribute to True. The Resolveexternals attribute prevents the parsing engine from parsing an external entity index, a document type definition, or an external name field.


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.