XML Server Getting Started    
XML objects in XMLSP scripting  
One of the specifics of XMLSP scripting is a heavy usage of XML objects as XML becomes 
de facto
 communication 
protocol across all tiers of the distributed system. This document does not attempt to cover all types of XML objects you may 
find useful while scripting XMLSP pages (see 
on line reference of XML Dom Objects/Interfaces at MSDN Library
). Instead, 
in this section we will focus on the most often used objects: XML Document, XML Node and XML Nodelist. 
XML Document objects are, strictly speaking, pointers to instances of 
DOMDocument interface
. Several methods of 
xmlapi
object (/xmlsp/htc/xmlapi.htc)    
XMLObject()
, 
XML(), XMLfromString(),  XMLHTTPRequest()
   are specifically provided as 
convenience methods all returning DOMDocument objects. Below we describe XMLObject(), XML() and 
XMLfromString(), while function XMLHTTPRequest() is explored in the separate section 
Accessing server side objects from 
the client code:  XML over HTTP calls.
Method 
XMLObject()
 simply returns pointer to a new DOMDocument interface. Method 
XML([url]) 
takes an optional 
argument to treat it as URL to synchronously load DOMDocument with XML stream returned by the URL. It may throw 
exception when the URL does not exist or returns non well formed XML. For examples, the following script will result in 
displaying the content of the entire XML document contained at  /Examples/controls.xml : 
var xmlDoc = xmlapi.XML("/Examples/controls.xml"); 
alert(xmlDoc.xml); 
Unlike method 
XML() 
which attempts to initialize XML document object with the data streamed out by URL, another 
method    
XMLfromString(xmlDocAsString)
 does it with script based string. This method also throws exception when the 
string does not contain a well formed XML.  
The most typical case of using 
XMLfromString()
 in XMLSP scripts is to package retrieval arguments along with the name of 
the connection pool into 
context
 object to be used by 
 in 
retrieve()
 and 
update()
 operations. For instance, in 
step0.jsp we have the following script to populating  customers  control: 
 function window::onLoad() { 
    customerList.connection =  asademo ; 
    customerList.retrieve(); 
 } 
which means passing  asademo  value as the name of the connection pool for XMLControl  customerList . This could have 
been changed to 
 function window::onLoad() { 
     customerList.context = xmlapi.XMLfromString("asademo"); 
     customerList.retrieve(); 
  } 
since when 
context
 property is not specified explicitly by the application, XMLControl builds one dynamically using 
connection
 value to populate 
currentsqlid
 node. Had we had to provide retrieval arguments, say to show only customers 
living in the state of New Jersey, we could have written something like: 
function window::onLoad() { 
    customerList.context = xmlapi.XMLfromString( 
"asademoNJ" 
    ); 
 2000 2002 Computer Technology Inc. All rights reserved. 
Page 11 




J2EE Web Hosting Tundra XML Server Pages J2EE Hosting




 
TotalRoute.net Business web hosting division of Vision Web Hosting Inc. All rights reserved.