XML Schemas XML Standards

page 20

1.2.4.5 Document Object Model DOM Level 1

The DOM, as we discussed earlier, is a programming API for documents. It defines a set of interfaces and methods used to view an XML document as a tree structure. XSLT and XPath use a similar tree view of XML documents. See http:www.w3.orgTRREC-DOM-Level-1 for more information.

1.2.4.6 Document Object Model DOM Level 2

The DOM Level 2 standard builds on DOM Level 1. It adds several new features: • HTML support, providing a DOM view of HTML documents • CSS and stylesheet interfaces • Document events • Tree traversal methods • Range selection methods • Views of DOM trees, in which the view is separate from the DOM itself The new features of DOM Level 2 dont affect our work directly. If you read the specification, youll see that certain features, such as views, stylesheet interfaces, and tree traversal, provide features useful to an XSLT processor. Although future XSLT processors will be built on XML parsers that provide these functions, that wont change any of the techniques we cover in this book. See http:www.w3.orgTRDOM-Level-2 for the complete specification.

1.2.4.7 Namespaces in XML

As we mentioned earlier, namespaces provide a way to avoid name collisions when two XML elements have the same name. See http:www.w3.orgTRREC-xml-names for more information.

1.2.4.8 Associating stylesheets with XML documents

Its possible to reference an XSLT stylesheet within an XML document. This specification uses processing instructions to define one or more stylesheets that should be used to transform an XML document. You can define different stylesheets to be used for different browsers. See http:www.w3.orgTRxml-stylesheet for complete information. Heres the start of an XML document, with two associated stylesheets: ?xml version=1.0? ?xml-stylesheet href=docbookhtmldocbook.xsl type=textxsl? ?xml-stylesheet href=docbookwapdocbook.xsl type=textxsl media=wap? In this example, the first stylesheet is the default because it doesnt have a media attribute. The second stylesheet will be used when the User-Agent field from the HTTP header contains the string wap , identifying the requester of a document as a WAP browser. The advantage of this technique is that you can define several different stylesheets within a particular document and have each stylesheet generate useful results for different browser or client types. The disadvantage of this technique is that were effectively putting rendering instructions into our XML document, something we prefer to avoid.