News:

This week IPhone 15 Pro winner is karn
You can be too a winner! Become the top poster of the week and win valuable prizes.  More details are You are not allowed to view links. Register or Login 

Main Menu

Save Data to an XML File

Started by ben2ong2, October 06, 2006, 04:39:41 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

ben2ong2

Usually, we save data in databases. However, if we want to make the data more portable, we can store the data in an XML file.

Create and Save an XML File
Storing data in XML files is useful if the data is to be sent to applications on non-Windows platforms. Remember that XML is portable across all platforms and the data will not need to be converted!
First we will learn how to create and save an XML file. The XML file below will be named "test.xml" and will be stored in the c directory on the server. We will use ASP and Microsoft's XMLDOM object to create and save the XML file:
<%Dim xmlDoc, rootEl, child1, child2, p'Create an XML documentSet xmlDoc = Server.CreateObject("Microsoft.XMLDOM")'Create a root element and append it to the documentSet rootEl = xmlDoc.createElement("root")xmlDoc.appendChild rootEl'Create and append child elementsSet child1 = xmlDoc.createElement("child1")Set child2 = xmlDoc.createElement("child2")rootEl.appendChild child1rootEl.appendChild child2'Add an XML processing instruction'and insert it before the root elementSet p=xmlDoc.createProcessingInstruction("xml","version='1.0'")xmlDoc.insertBefore p,xmlDoc.childNodes(0)'Save the XML file to the c You are not allowed to view links. Register or Login "c:\test.xml"%>
If you open the saved XML file it will look something like this ("test.xml"):
<?xml version="1.0"?><root>  <child1 />  <child2 /></root>
You are not allowed to view links. Register or Login
You are not allowed to view links. Register or Login