Generating XML Using ASP

The following example shows you the process by which a server-side scripting language, in this can be used to generate an XML document. The scripting language is called ASP (Active Server Pages) and uses the XML DOM:

   <% Set XMLDoc = Server.CreateObject ("Microsoft.XMLDOM") rem Create the root element weatherForceast and attach it to the XML document Set weatherForecast = XMLDoc.createElement ("weatherForecast") Set dateAttr = XMLDoc.createAttribute ("date") dateAttr.Text = "3/2/99" weatherForecast.attributes.setNamedItem (dateAttr) Set XMLDoc.documentElement = weatherForecast rem Add the first vacation resort to a list of resorts Set resort = XMLDoc.createElement ("resort") weatherForecast.appendChild (resort) set name = XMLDoc.createElement ("name") name.Text = "Meribel" resort.appendChild (name) rem Create the temperature element within the first resort Set temperatures = XMLDoc.createElement ("temperatures") resort.appendChild (temperatures) rem Create the minimum temperatute Set min = XMLDoc.createElement ("min") min.Text = "80" temperatures.appendChild (min) rem Create the maximum temperatute Set max = XMLDoc.createElement ("max") max.Text = "105" temperatures.appendChild (max) Response.Write "<?xml version=""1.0""?>" Response.Write XMLDoc.xml %>   

The preceding example consists of only a single resort because it is all hard coded and written directly into a browser by ASP. The browser response is shown in Figure 2-20.

image from book
Figure 2-20: The results of a processed ASP script

If you go into the source for your browser page after you have executed the ASP script, you will find that the XML document produced will look like that shown here (I have added new lines and formatting to make it easier to read):

   <?xml version="1.0"?> <weatherForecast date="3/2/99">    <resort>       <name>Meribel</name>       <temperatures>          <min>80</min>          <max>105</max>       </temperatures>    </resort> </weatherForecast>   


Beginning XML Databases
Beginning XML Databases (Wrox Beginning Guides)
ISBN: 0471791202
EAN: 2147483647
Year: 2006
Pages: 183
Authors: Gavin Powell

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net