org.jaxen.dom.html
Class HTMLXPath

java.lang.Object
  |
  +--org.jaxen.BaseXPath
        |
        +--org.jaxen.dom.html.HTMLXPath
All Implemented Interfaces:
Serializable, XPath

public class HTMLXPath
extends BaseXPath

An XPath implementation for the W3C HTML DOM model

This is an XPath providing element and attribute case-management for HTML documents. Because HTML is case-insensitive, but stores DOM elements in upper case, it is difficult to write XPath queries for HTML documents which are also compatible with their XHTML equivalents. This class converts the element, but not attribute, names of an HTML document to upper or lower case, depending on your specification, so that lower case [element] xpath expressions will work just as well on HTML as they do on XHTML (which is case sensitive and enforces lower case on elements and attributes). Note that HTML attribute names are stored as lower case in the HTML (and XHTML) DOM already which is why the case of attribute names are not modified.

You create a compiled XPath object, then match it against one or more context nodes using the BaseXPath.selectNodes(java.lang.Object) method, as in the following example:

 XPath path = new HTMLXPath("a/b/c", true); // convert to lower case
 List results = path.selectNodes(htmlNode);
 

Version:
$Revision: 1.1 $
Author:
David Peterson
See Also:
BaseXPath, DOMXPath, Serialized Form

Constructor Summary
HTMLXPath(String xpathExpr)
          Constructs a new XPath, treating all elements as lower case.
HTMLXPath(String xpathExpr, boolean toLowerCase)
          Construct given an XPath expression string.
 
Methods inherited from class org.jaxen.BaseXPath
addNamespace, booleanValueOf, createFunctionContext, createNamespaceContext, createVariableContext, debug, evaluate, getContext, getContextSupport, getFunctionContext, getNamespaceContext, getNavigator, getRootExpr, getVariableContext, numberValueOf, selectNodes, selectNodesForContext, selectSingleNode, selectSingleNodeForContext, setFunctionContext, setNamespaceContext, setVariableContext, stringValueOf, toString, valueOf
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

HTMLXPath

public HTMLXPath(String xpathExpr,
                 boolean toLowerCase)
          throws JaxenException
Construct given an XPath expression string.

Parameters:
xpathExpr - The XPath expression.
toLowerCase - If true, all element names will be considered to be lower case. Otherwise, they will be upper case.
Throws:
JaxenException - if there is a syntax error while parsing the expression.

HTMLXPath

public HTMLXPath(String xpathExpr)
          throws JaxenException
Constructs a new XPath, treating all elements as lower case.

Parameters:
xpathExpr -
Throws:
JaxenException


Copyright © 2001-2003 Codehaus. All Rights Reserved.