If you can read this, it's time you upgrade that browser of yours to one that supports the Web Standards.
 .XMLObject()   .about()   .reference()   .download()   .examples()   .support() 

Code examples

There isn't that much to learn, except from learning how to create the object and use its features, but before we do that, you'll need to know that XMLObject() uses the MSXML Parser and some of its extensions to the W3C's XML Specification, though anyone who's been using other XML Parsers should have no trouble tweaking the code to work with them.

There are several ways to utilize the XMLObject from within an ASP page, but the basic principles are to 1) Include the xmlobject.asp file (this is assumed in all examples); 2) Create an instance of XMLObject(), using one of the constructors, and 3) Get the transformed result, or perform some manipulations.

The code examples are all using JScript ASP. Here we go:

Simple transformation

This example simply outputs the result of transforming links.xml with the stylesheet transform.xsl. If errors occur (or the xml documents aren't well-formed), an error description is output instead.

	 var oXML = new XMLObject("links.xml", "transform.xsl");
	 Response.Write((oXML.error ? oXML.errorDesc : oXML.output));

You can make it even simpler by using the quickTransformXML function that became available in version 2.7:

<%= quickTransformXML("links.xml", "transform.xsl") %>

— or if you'd like to avoid any errors that might occur:

<%= quickTransformXML("links.xml", "transform.xsl", XMLOBJ_NO_ERRORS) %>
Using StyleSheet parameters

In this example, a QueryString parameter is passed to the XSLT StyleSheet before transforming, which is a very useful technique which — quite frankly — is a major pain to perform "manually", because it involves creating an XSLTemplate Object from which you get an XSLProcessor Object — a compiled stylesheet — that can receive parameters to transfer to the stylesheet.

In the example, the QueryString has a variable named "sel", whose value gets transferred to the stylesheet variable "selectedLink". (In the XSLT Stylesheet you would refer to this with "$selectedLink").

This one uses the XSLTemplate object and caches the XML documents in Application variables which means that when you change these documents you must call the .asp page using them with the following QueryString: reloadprocessors=yes, atleast once after you've uploaded the changes.

	 var oXML = new XMLObject("links.xml", "transform.xsl", "sel->selectedLink");
	 Response.Write((oXML.error ? oXML.errorDesc : oXML.output));
Combining two XML documents before transforming

The manipulator methods of XMLObject allows for some basic editing functionality, using some shortcuts to the XMLDOM Interface methods. The implemented manipulators are .appendToRoot(), .removeNode() and .replaceNode(). We'll use replaceNode here, to demonstrate the process.

The first document contains an XML element named <Include-File-Here/>, which acts as a placeholder for the included second document. When we load the first document along with the stylesheet, we use the XMLOBJ_NO_TRANSFORM constant to tell the XMLObject not to perform the transform. Afterwards, we specify that our placeholder element is to be replaced with the contents of the document seconddoc.xml.

Lastly, we call .transform(), and print the output to the client...

	 var oXML = new XMLObject("firstdoc.xml", "stylesheet.xsl", XMLOBJ_NO_TRANSFORM);
	 oXML.replaceNode("seconddoc.xml", "//Include-File-Here");
	 Response.Write((oXML.error ? oXML.errorDesc : oXML.output));

(More examples to come...)


@19-10-2002 00:45 (v2.8.5)
Separate caching of XML or XSL using bitflags. Bugfix when loading via HTTP and using caching. New optional argument for .appendToRoot(). New property .useXPath.
@25-08-2002 23:36 (v2.8.4)
Added support for ServerXMLHTTP when loading XML from URLs.
@30-04-2002 01:23 (v2.8.3)
Added a new constant: XMLOBJ_DEFAULT_VERSION and a new method: .appendToNode().
@22-03-2002 00:21 (v2.8.2)
Bugfix: Using .setVersion() worked, but would throw an error anyway. Additionally, version 4 PROGIDs were supported, but the "4.0" registered as "Not supported"...
@23-02-2002 02:25 (v2.8.1)
Bugfix: Using .replaceNode() in conjunction with the caching mechanisms threw an error about mixed threading models.
@14-01-2002 00:20 (v2.8)
Fixed some bugs with Version-Dependent ProgIDs, and loading via URLs. Added support for the MSXML4 Parser. Added the constants to the Reference section.
@22-11-2001 01:31 (v2.7)
New function: quickTransformXML, and a new constant: XMLOBJ_NO_ERRORS was added to the interface.
@01-11-2001 00:12 (v2.6)
Implemented .getNodeText().
@31-10-2001 20:35 (v2.6)
Fixed a bug with parameters that wasn't specified in the QueryString being transferred to the stylesheet as "undefined". Now only specified parameters are transferred, which allows for default values in the stylesheet.
@23-10-2001 22:38 (v2.5)
Implemented .removeNode() method.
@23-10-2001 01:42 (v2.5)
Uploaded the website.
@18-10-2001 22:01 (v2.5)
Implemented .saveXML(), .replaceNode() and .appendToRoot() methods. Removed interface description from xmlobject.asp.
@02-10-2001 21:24 (v2.2)
Implemented property .validateOnParse
@26-09-2001 22:16 (v2.1)
Refined handling of cached documents - if another page uses the same file, and sets the XMLOBJ_USE_XSLTEMPLATE flag, the XMLObject will look for a cached version before trying to load a fresh document.
@21-09-2001 00:26 (v2.0)
Reworked logic for the 3rd parameter of constructor to use bitflags. Enables use of XSLTemplate together with XMLOBJ_NO_TRANSFORM.
@18-09-2001 00:19 (v2.0)
Implemented .validate() method.
@16-09-2001 00:25 (v2.0)
Implemented access to .addParameter() and .addObject() in the XSLProcessor.
@15-09-2001 02:21 (v2.0)
Succeeded in implementing the XSLTemplate object INCLUDING parameters from QueryString being transferred to the XSLProcessor!!!
@14-09-2001 02:29 (v1.1)
Pieced the documentation together, which contains XML and XSLT - and they are using this object for showing...
@13-09-2001 20:14 (v1.0)
Moved interface functions inside constructor for better encapsulation.
@30-08-2001 22:45 (v1.0)
Fixed the seemingly incredibly buggy .xml + .xsl properties, as they hadn't really been implemented -:)
@29-08-2001 01:04 (v0.1)
Implemented the loading methods .loadXMLdoc() + .loadXSLdoc()
@28-08-2001 00:05 (v0.1)
First successful tests. Lots of minor bugtracking & -fixing.
@26-08-2001 20:44 (v0.1)
Project started. Interface layout. Coding.
HTML 4.01  CSS