The libXmlRequest.js script file contains all of the procedures used by the examples available on this page.
The sample_data.xml XML file is used for demonstration data.
To make use of this library, copy the libXmlRequest.js file to your server or local machine, and reference it from a particular web page.
For example: <script type="text/javascript" src="libXmlRequest.js"></script>
The XmlRequest library contains a two public request functions, getXml and postXml, that may be used to send synchronous and asynchronous XML Http requests from Internet Explorer and Mozilla.
The syntax for each function follows.
[xml_document] = getXml(sPath): a synchronous GET request, returns null or an xml document object
[int] = getXml(sPath,fHandler,1): an asynchronous GET request, returns '1' if the request was made, and invokes handler 'fHandler' when the xml document is loaded.
[xml_document] = postXml(sPath,vData): a synchronous POST request, returns null or an xml document object. Note that this expects the server will respond with well-formed XML. If it doesn't, the response xml object will be null. The responseText is not queried.
[int] = postXml(sPath,vData,fHandler,1): an asynchronous POST request, returns '1' if the request was made, and invokes handler 'fHandler' when the xml document is loaded. Note that this expects the server will respond with well-formed XML. If it doesn't, the response xml object will be null. The responseText is not queried.
Example: var oXml = getXml("sample_data.xml");
The following property accessors are exposed:
setCacheEnabled([true | false])
[true | false] = getCacheEnabled()
setPoolEnabled([true | false])
[true | false] = getPoolEnabled()
[oInternalObject] = getXmlHttpArray() : returns an array of pool objects.
clearCache() : clears cached XML DOM references.
[true | false] = testXmlHttpObject() : tests whether an XmlHttpObject can be created.
In addition, the following utility functions are provided.
[xml_document] = newXmlDocument(sNodeName): returns a new XML document object with the specified root node name.
[string] = serialize(oNode): returns the string representation of a node.
[array] = selectNodes(xmlDocument,sXpath,oNode): returns an array of results based on the specified XPath for a given XML document.
[node] = selectSingleNode(xmlDocument,sXpath,oNode): returns a single XML node based no the specified XPath for a given XML document. Note: the node reference is required for this implementation to work with Mozilla.
removeChildren(node): removes all children from an HTML or XML DOM node.
setInnerXHTML(target_node,source_node,preserve): copies the source_node (XML or HTML) structure into target_node (HTML).