eHow launches Android app: Get the best of eHow on the go.

How To

How to Create an XML Document with ASP

Contributor
By eHow Contributing Writer
(1 Ratings)

XML, which stands for extensible markup language, is a document standard used to make files with records of information. The file format looks similar to HTML in that it uses opening and closing tags with properties and data information enclosed in the tags. Writing XML pages can be done through ASP code with the use of "nodes." The documents can be saved to the web server, or they can be displayed to the browser. Browsers use XML to view structured data records. As data techniques become more advanced, XML is used to easily retrieve and display records for users.

Difficulty: Moderate
Instructions
  1. Step 1

    Create the XML object with a file name. The code below creates the XML object that is used throughout the code to read, write, and display the records:
    set xmlfile = Server.CreateObject("myfile.Xml")

  2. Step 2

    Create the top node. In this example, the application saves a list of customers with their first name and last name. The top node tag is "customers" and it holds all the records:
    xmlfile.Tag = "customers"

  3. Step 3

    Create a child node for the first customer. This indicates the first record for a new customer. It contains the information that is unique to the record:
    set xmlfile = xmlfile.NewChild("customer", "")

  4. Step 4

    Populate the "customer" node with the information. The code below adds the customer's first and last name to the record:
    xmlfile.NewChild2 "First_Name", "Joe"
    xmlfile.NewChild2 "Last_Name", "Smith"

  5. Step 5

    Move back up the tree and create another customer record. There is no need to close the record tags in XML. The object knows to move to the next record. The "GetParent()" method moves to the next record. The code below adds another customer record using the "customer" node tag:
    xmlfile.GetParent2()
    xmlfile.NewChild2 "First_Name", "Pam"
    xmlfile.NewChild2 "Last_Name", "Jones"

  6. Step 6

    Display the XML document. The following code displays the new XML document to the browser:
    response.write xmlfile.GetXml()

References

Subscribe

Post a Comment

Post a Comment

Related Ads

  • Have you done this? Click here to let us know.
I Did This
Get Free Internet Newsletters

Copyright © 1999-2009 eHow, Inc. Use of this web site constitutes acceptance of the eHow Terms of Use and Privacy Policy .   en-US Portions of this page are modifications based on work created and shared by Google and used according to terms described in the Creative Commons 3.0 Attribution License. † requires javascript

Demand Media
eHow_eHow Technology and Electronics