libXmlRequest
[ whitefrost.com | Stephen W. Cote ]
Refer to libXmlRequest SPEC-1.5.1.0909.2005 for the latest version.
Version: SPEC-1.1.102.1706.2003.
Download: libXmlRequest.js.
Demonstration: Example Suite. Also refer to example at the bottom of this page.
The Example Suite for this version serves as a decent stress test (similar to the following Example #3). Refer to the previous references libXmlRequest 1.0.0.11.04.2002 and libXmlRequest SPEC-1.0.39.02.03.2003 for addition examples. Refer to the XML Utility Example #2 and XML Utility Example #3 (Engine for Web Applications) for further examples of the cache and pool features.
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).
- [node | null] = transformNode([xml_dom | xml_path], [xsl_dom | xsl_path] {, node_reference, xml_request_id, xsl_request_id, bool_cache_xsl})
Example:
var oXml = getXml("sample_data.xml");
var aNodes = selectNodes(oXml,"/sample-data-root/the-data",oXml.documentElement);
<sample-data-root> <the-data id="data1"/> <the-data id="data2"/> <the-data id="data3"/> <the-data id="data4"/> <the-data id="data5"/> <the-data id="data6"> <some-html> <p>here is an example paragraph</p> <p>here is another <b>example paragraph with bold</b>.</p> </some-html> </the-data> </sample-data-root>
<!-- BEGIN -->
here is an example paragraph
here is another example paragraph with bold.
<!-- END -->