Generating XML using the XML DOM (3)

Source: Internet
Author: User
Tags add date
dom|xml| generate XML to assign values to nodes
Once you create an endpoint, you also assign a value to its properties, such as a stand-alone identifier, or an attribute value. You have to use the SetAttribute method. The method receives two parameters-property names and property values. For example, the following code creates the property name Shipping_datasource and the property value north_atlantic_shipping:

Objxmlroot.setattribute _

"Shipping_datasource", _

"North_atlantic_shipping"

At this point, we generate the XML document for Figure B.



Figure B:setattributes method to create an ending point property

Add Sub Node
To create a child node, you can use the createelement or CreateNode methods we described earlier and add them to the appropriate parent node. For example, suppose we were to create an XML node called Publisher_disclaimer. To do this, we attach the node to the root node of the document, and the code is as follows:

Set Objxmlchildtestnode = objXMLDoc _

. CreateNode ("element", _

"Publisher_disclaimer", "" ")



Objxmldoc.documentelement _

. appendchild (Objxmlchildtestnode



)


Note: We use the XMLDOMDocument documentelement feature to add new nodes to the root node of the XML document, see Figure C.



Figure C: To add child nodes, you just add them to your parent node.

Assign a value to a node
Once you have created all of the nodes, you will need to assign them a value. That is the most critical step in XML. To do this, as usual, create a node and assign a value to the node's Text property. For example, the following code creates an XML node called Published_date, and then assigns the following values:

Set Objpublishdate = objXMLDoc _

. CreateNode ("element", _

"Published_date", "" ")



Dshippeddate = FormatDateTime (Date, 2)

Objpublishdate.text = Dshippeddate



Objxmlchildtestnode.appendchild _

(objpublishdate)


As a result, see Figure D.



Figure D: We assign the current date to the Published_date Text property, and then add the node to the Publisher_disclaimer element.

We have now introduced the basics of several XML DOM, and here's how to use the XML DOM under ASP.



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.