![]() Capt. Horatio T.P. Webb | Receiving and Creating XML on the Server Parks -- FALL 2000 |
The following three methods can be used to get XML to the server:
First an XML object must be created on the server using:
Set object-name= Server.CreateObject("Microsoft.XMLDOM")
Then are three methods to load the XML data:
The following asp code sets up an object (xmlReq) to receive the XML file from the client:
Set xmlReq = Server.CreateObject("Microsoft.XMLDOM") xmlReq.load(Request) if xmlReq.parseError <> 0 then Response.write xmlReq.parseError.reason end if |
The object-name.load(Request) method takes the xml sent from the client using XMLHTTP and loads it to an XMLDOM object.
Once the XML is loaded to an object, the XML can be parsed. One can now
Here is an XML file stored as a textarea.
Click here to see the source code.
See also Sending XML from the Client for a discussion of XMLHTTP on the client.
We can get a string of XML several ways:
To utilize the XMLDOM to manipulate the tree we must hand the XML string to the XMLDOM (regardless of how we created the XML string). Like this:
xmls="<toptag><first>1</first><second>2</second><third>3</third></toptag>"
Click here to see the result.
If the XML file is locally stored on the server, you can load the data from the file to the XMLDOM by using:
Set xmlsample = Server.CreateObject("Microsoft.XMLDOM")
Note that the Server.MapPath assume the XML file is stored in the same directory as the asp. Otherwise you must use the full path name (e.g., "c:\somedir\actualfilename.xml").
Click here to see the source code.
Building an XML object from a string
Set xmla = Server.CreateObject("Microsoft.XMLDOM")
xmla.loadXML(xmls)
Click here to see the source code.
xmlsample.validateOnParse=True
xmlsample.async=False
xmlsample.load(Server.MapPath("xml4b.xml"))
Click here to see the result.