P.3 XML-Related Technologies

  Previous section   Next section

This section describes some of the technologies related to XML?namely, XPath, XSL, and SOAP.

P.3.1 XPath

XPath, the XML Path Language, provides common syntax and semantics for locating and linking to information contained within an XML document. Using XPath the information can be addressed in two ways:

  • A hierarchical fashion based on the ordering of elements in a document tree

  • An arbitrary manner relying on elements in a document tree having unique identifiers

A few example XPath expressions, based on the sample XML document in Listing P.2, are shown in Listing P.7. Example 1 expresses all children named firstname in the current focus element. Example 2 selects the child node surname whose parent node is name within the current focus element, while example 3 tests whether an element is present in the union of the elements name and address. Note that, although not shown in the examples, it is also possible to specify constraints such as first address of the third person in the document.

Listing P.7 Example XPath Expressions
1. select="firstname"
2. select="name/surname"
3. match="name | address"

P.3.2 XSL

Since an XML document does not contain any representational information, it can be formatted in a flexible manner. A standard approach to formatting XML documents is using XSL, the eXtensible Stylesheet Language. The W3C XSL specification is composed of two parts: XSL Formatting Objects (XSL FO) and XSL Transformations (XSLT).

XSL FO provides formatting and flow semantics for rendering an XML document. A rendering agent is responsible for interpreting the abstract constructs provided by XSL FO in order to instantiate the representation for a particular medium.

XSLT offers constructs to transform information from one organization to another. Although designed to transform an XML vocabulary to an XSL FO vocabulary, XSLT can be used for a range of transformations including those to HTML as shown in Listing P.8. The example style sheet uses a set of simple XSLT templates and XPath expressions to transform a part of the XML document in Listing P.2 to HTML (see Listing P.9).

Listing P.8 An XSL Style Sheet for the XML Document in Listing P.2
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl=
    "http://www.w3.org/1999/XSL/Transform" version="1.0">
   <xsl:template match="/">
      <html>
         <head><title>Person Information</title></head>
         <body>
            <xsl:apply-templates select="person/name"/>
         </body>
      </html>
   </xsl:template>
   <xsl:template match="name">
      <xsl:apply-templates/>
   </xsl:template>
   <xsl:template match="surname">
      <p><b><xsl:text>Surname: </xsl:text></b>
       <xsl:value-of select="."/></p><br/>
   </xsl:template>
   <xsl:template match="firstname">
      <p><b><xsl:text>First name: </xsl:text></b>
      <xsl:value-of select="."/></p>
   </xsl:template>
</xsl:stylesheet>
Listing P.9 HTML Resulting from the Transformation in Listing P.8
<html>
   <head>
      <title>Person Information </title>
   </head>
   <body>
      <p>
         <b>Surname: </b>Doe
      </p>
      <br>
      <p>
      <b>First name: </b>John
      </p>
   </body>
</html>

P.3.3 SOAP

SOAP is the Simple Object Access Protocol used to invoke code over the Internet using XML and HTTP. The mechanism is similar to Java Remote Method Invocation (RMI). In SOAP, method calls are converted to XML and transmitted over HTTP. SOAP was designed for compatibility with XML schemas though their use is not mandatory. Being based on XML, XML schemas offer a seamless means to describe and transmit SOAP types.


Top

Part IV: Applications of XML