-
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") -
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" -
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", "") -
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" -
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" -
Step 6
Display the XML document. The following code displays the new XML document to the browser:
response.write xmlfile.GetXml()












