Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs
The XPath tag library provides a framework within which dynamic content represented as a DOM document can be manipulated and inserted into a JSP to:
The XPath tag library combined with JSP further aids efficiency by engendering a clear separation between the role of a page author and a programmer.
This article covers intermediate-to-advanced JSP, XML, and DOM topics, so you may need to do some background reading in Resources to get up to speed.
Note: The XPath custom tag library is still in the proof-of-concept stage, hence it is not available as a standalone tag library. However, you can download the XPath-JSP Test Application WAR file and extract the relevant parts to create your own standalone tag library.
XPath, a W3C recommendation since November 1999, provides an easy notation for specifying and selecting parts of an XML document. An XML document is a tree of elements with only one route or path from the root node of the tree to any other node of the tree. XPath defines this path.
Let's take an example XML document and some XPath expressions used to locate its parts.
The document below represents a user who has a userid and a password. Moreover, a user can have multiple roles, in this case
Domain Administrator and
Help Desk Administrator:
<user> <userid>someone</userid> <password>somewhere</password> <roles> <role id="admin">Domain Administrator</role> <role id="helpdesk">Help Desk Administrator</role> </roles> </user>
The basic XPath syntax is similar to filesystem addressing. As such, if the path starts with
/, then it represents an absolute path to the required element:
/user/userid/text() select 'someone' /user/roles/role select all 'role' elements //role select all 'role' elements [ same as 2.] //role[@id='admin']/text() select 'Domain Administrator' /user/roles/role select the first role element i.e. 'Domain Administrator' /user/roles/role[last()] select the last role element i.e. 'Help Desk Administrator'
The above examples represent just a sample of XPath's power. For a more complete list of XPath syntax see the XPath tutorial in Resources.
Having seen how XPath expressions can be used on an XML document, let us now discuss the architecture of a Web application using the XPath custom tag library, illustrated in Figure 1.