COM 3360 Fall 99 Term Project
Part 1
Evaluating Xpath for Structure-Shyness
Submitted by : Vibhas & Prakash.
Faculty : Prof Karl Lieberherr.
Index
Looking at Structure-Shyness of Xpath
*Summary
*Xpath Basics
*Defining Structure-Shyness
*Analysis Approach
*Tool(s) Used.
*Test Cases.
*Verifying Results.
*Online Resources
*Conclusion
*
Looking at Structure-Shyness of Xpath
Xpath is a standard from W3C (a "recommendation" in W3C parlance) that can be used to navigate/address parts of an XML document and is meant to be used with XSLT & XPointer standards from W3C which are the languages for document-transformation and Multi-directional links respectively. This project attempts to evaluate the structure-shyness of Xpath.
Xpath is used in conjunction with XSLT & XPointer standards. XSLT (XML Style Language Transformations) is used to convert XML document from one form to another (typically HTML). It takes two input files - an XML document along with it’s DTD or equivalent and an XSLT language instructions file and outputs another xml document. XPointer specifies complex Links like bi-directional links and allows the location of a specific part of XML document. Any fragment identifier that points into an XML resource must be an Xpointer.
Both these languages need to navigate an XML document and hence the navigation part was extracted out as a separate language – Xpath.
XPath gets its name from the use of a path notation as in URLs for navigating through the hierarchical structure of an XML document. It uses a compact, non-XML syntax to facilitate it’s use within URIs and XML attribute values and operates on the abstract, logical structure of an XML document, rather than its surface syntax. The primary syntactic structure of XML is an expression that evaluates to yield an object which can be one of the four types below:
Expression evaluation occurs with respect to a context. XSLT and XPointer specify how the context is determined for XPath expressions used in XSLT and XPointer respectively. The context consists of:
The patterns can be matched using notations shown below
|
Symbol |
Meaning |
Example |
|
/ |
Gets all matching children |
Chapter / Section / * : will give nodes that childern of the node "Section" and grandchildren of the node "Chapter". |
|
// |
Gets all matching descendants` |
Chapter // Paragraph : Will return all paragraphs that are descendants of the Chapter node no matter how many nodes come in between. |
|
@ |
Gets all matching attributes |
@UNITS : will return value of the UNITS attribute for the current node. |
|
Comment() |
Gets the comment node |
Chapter / * / comment() : Will return the comment node (tag) of all children nodes belonging to the chapter node. |
|
[ ] |
Gets nodes satisfying a condition. |
Chapter [Annotation] : Will return Chapter nodes that contain Annotation attribute (assuming the attribute is optional). |
Since Xpath is an emerging standard (started in April 1999 and version 1.0 was published only this month), not many tools were found to support this yet. Of those that were found (for example Caucho ‘s Resin 1.0 ) supplied Xpath Java APIs that had to be coded in a program to create our testing tool. We decided to use a tool that required minimum efforts to set up the testing tool. The best appears to be a tool called XT that was written by James Clark (author of W3C ‘s Xpath).
XT is a Java utility that needs two input files - a .xml file containing XML document and .xsl file containing XSLT intructions with embedded Xpath instructions. The output (in our case) would be a .html file. No compiling or elaborate coding is necessary to test the various navigational combinations.
Here is an example of .xml file
<?xml version="1.0"?>
<?xml-stylesheet type="text/xml" href="14-2.xsl"?>
<PERIODIC_TABLE>
<ATOM STATE="GAS">
<NAME>Hydrogen</NAME>
<SYMBOL>H</SYMBOL>
<ATOMIC_NUMBER>1</ATOMIC_NUMBER>
<ATOMIC_WEIGHT>1.00794</ATOMIC_WEIGHT>
<BOILING_POINT UNITS="Kelvin">20.28</BOILING_POINT>
<MELTING_POINT UNITS="Kelvin">13.81</MELTING_POINT>
<DENSITY UNITS="grams/cubic centimeter"><!-- At 300K -->
0.0899
</DENSITY>
</ATOM>
<ATOM STATE="GAS">
<NAME>Helium</NAME>
<SYMBOL>He</SYMBOL>
<ATOMIC_NUMBER>2</ATOMIC_NUMBER>
<ATOMIC_WEIGHT>4.0026</ATOMIC_WEIGHT>
<BOILING_POINT UNITS="Kelvin">4.216</BOILING_POINT>
<MELTING_POINT UNITS="Kelvin">0.95</MELTING_POINT>
<DENSITY UNITS="grams/cubic centimeter"><!-- At 300K -->
0.1785
</DENSITY>
</ATOM>
</PERIODIC_TABLE>
And here is an example of .xsl file with embedded Xpath instructions. The SELECT and MATCH attributes in the file below can contain any valid Xpath expression.
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/PERIODIC_TABLE/*">
<html>
<body>
<h1>Atomic Number vs. Melting Point</h1>
<table>
<th>Element</th>
<th>Atomic Number</th>
<th>Melting Point</th>
<xsl:apply-templates/>
</table>
</body>
</html>
</xsl:template>
<xsl:template match="ATOM">
<tr>
<td>
<xsl:value-of select="NAME"/>
</td>
<td>
<xsl:value-of select="child::ATOMIC_NUMBER"/> <- Alt Syntax
</td>
<td>
<xsl:value-of select=" ATOMIC_NUMBER|ATOMIC_WEIGHT|SYMBOL"/>
</td>
</tr>
</xsl:template>
<xsl:template match="MELTING_POINT">
<xsl:value-of select="."/>
<xsl:value-of select="@UNITS"/>
</xsl:template>
</xsl:stylesheet>
We are in the process of setting up test cases for the various combinations of @, /, / and of-course making use of the wild card character - *.