Library sample chapters

Using XML Queries and Transformations

IE5 Conformance

IE5 implements a subset of XPath. If you are developing for the MSXML objects in the initial IE5 release, you have to know what features are implemented in XPath and which are not. Microsoft has committed to implementing the full standard in all later versions. It is unclear what backward compatibility will exist with syntax elements that are not part of the W3C recommendation. Here we will show the differences between the IE5 implementation and the W3C recommendation 1.0.

Axes

IE5 knows only the abbreviated syntax for axis and node test. You cannot use the syntax with a double colon. This limits the number of axes, because not all XPath axes have an abbreviated form (for example namespace, ancestor, following, preceding).

Functions

Not all of the built-in functions of XPath are supported in IE5. The most notable difference is the last() function which is called end() in IE5. Also, many functions are not supported at all. Here is a full list of the supported functions in IE5:

  • attribute() returns all attribute nodes of the context node.
  • cdata() returns all CDATA nodes that are children of the context node.
  • comment() returns all comment nodes that are children of the context node.
  • date() casts a value to date format.
  • element() returns all elements that are children of the context node.
  • end() is synonymous to last() in the XPath recommendation.
  • index() returns the index number of the node within its parent.
  • node() returns all nodes (except attributes and the root node) that are children of the context node.
  • nodeName() returns the tag name (includes namespace prefix).
  • nodeType() returns a number indicating the node type.
  • number() casts values to number format.
  • pi() returns all processing instruction nodes that are children of the context node.
  • text() returns all nodes that represent a text value, that are children of the context node. This includes both text nodes and CDATA nodes.
  • textnode() returns all text nodes that are children of the context node.
  • value() returns the value of an element or attribute.
  • Examples

    In the source code download, you will find a small Visual Basic application, called XPathTester.vbp, which allows you to both practice the writing of XPath queries and test their performance. If you start the application, you will see this form:

    The Query tester frame can be used once an XML document is loaded. After loading such a document (take a big one like Macbeth.xml), you can see the structure of the document in the tree view control to the left. If you select a node and type an XPath expression in the Query text box, you can execute this query, using the selected node as your context node. All matching nodes are listed in the list box. If you click a list item, the underlying XML source is shown in the text box on the right. Note that the number of seconds needed for performing the query is shown directly under the list box. Use this application to practice writing queries. Notice how more specific queries have a better performance than very general ones. Also, queries that specify the structural relations of elements are much faster than queries specifying the text content of elements and attributes.

    Comments

    1. 02 Nov 2004 at 14:03

      The table under "format attribute" on the following page also seems to be truncated:  http://www.developerfusion.com/show/89/10/

    2. 16 Jun 2002 at 12:01

      my apologies for that, it appears the article became truncated. The rest of the text on 'giving style to  XML' is now there.


      Regards,

    3. 16 Jun 2002 at 10:25

      The 'giving style to XML' part of the article (which is the only part that interested me, sigh) is apparently corrupt - It ends in the middle of a sentence, and so it doesn't explain one bit of what it promises to...

    4. 01 Jan 1999 at 00:00

      This thread is for discussions of Using XML Queries and Transformations.

    Leave a comment

    Sign in or Join us (it's free).

    AddThis

    Want to stay in touch with what's going on? Follow us on twitter!