com.japisoft.xpath
Class XPath

java.lang.Object
  |
  +--com.japisoft.xpath.XPath

public class XPath
extends java.lang.Object

Here the main class for Parsing and Resolving an XPath expression. You just have to set your XPathException with the setXPathExpression and choose a node for application with the setReferenceNode. Finally the resolution is made by the resolve method.

Version:
1.3
Author:
(c) 2003 JAPISoft

Constructor Summary
XPath()
          This constructor searches the Kit using the system property com.japisoft.jxp.kit.
XPath(XPathKit kit)
          Here we pass a kit specific to the XML tree format like DOM, JDOM, fastParser lightweight node
 
Method Summary
 void addNamespaceDeclaration(java.lang.String prefix, java.lang.String uri)
          Add a namespace declaration If this prefix apperars in the XPath expression then the tied uri if used for discovering node from the uri namespace
 void addVariable(java.lang.String name, boolean value)
          Set a variable value from the XPath expression
 void addVariable(java.lang.String name, double value)
          Set a variable value from the XPath expression
 void addVariable(java.lang.String name, int value)
          Set a variable value from the XPath expression
 void addVariable(java.lang.String name, NodeSet value)
          Set a variable value from the XPath expression
 void addVariable(java.lang.String name, java.lang.String value)
          Set a variable value from the XPath expression
 java.lang.String[] getSupportedFeatures()
          Return a list of supported features by the current kit
 boolean hasNavigatorCache()
           
 boolean isFeatureSupported(java.lang.String feature)
           
 void removeNamespaceDeclaration(java.lang.String prefix)
          Remove a namespace declaration for this prefix
 void removeVariable(java.lang.String name)
          Remove the variable binding for this name, if an XPath expression contains this name, an error will be thrown
 NodeSet resolve()
          Resolve the XPath expression for the reference node.
 java.lang.Object resolveAny()
          Resolve the XPath expression, user has to cast correctly the result as NodeSet, String, Double Boolean
 void setFeature(java.lang.String feature, boolean enable)
          Set a feature support for the current kit.
 void setNavigatorCache(boolean cache)
          Reset the cache for the navigator part.
 void setReferenceNode(java.lang.Object node)
          Reset the reference node for resolution.
 void setXPathExpression(java.lang.String expr)
          Reset the XPath expression.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XPath

public XPath(XPathKit kit)
Here we pass a kit specific to the XML tree format like DOM, JDOM, fastParser lightweight node


XPath

public XPath()
This constructor searches the Kit using the system property com.japisoft.jxp.kit. An Runtime exception is thrown is the property is not defined or if the kit provided is not found

Method Detail

setNavigatorCache

public void setNavigatorCache(boolean cache)
Reset the cache for the navigator part. By default to true. Note that this method could create more memory usage. If you use very large document it may be better to disable it. If you alter your document after parsing, you Must disable it for avoiding bad XPath result.


hasNavigatorCache

public boolean hasNavigatorCache()
Returns:
if the navigator cache is available. By default to true

setReferenceNode

public void setReferenceNode(java.lang.Object node)
Reset the reference node for resolution. It may be the root node. This element is required before evaluate the current expression


setXPathExpression

public void setXPathExpression(java.lang.String expr)
                        throws XPathException
Reset the XPath expression. This method should be called once for each XPath expression because a pre-parsing is made. If the expression is invalid an exception XPathException is thrown.

Parameters:
expr - an XPath expression
XPathException

resolve

public NodeSet resolve()
                throws XPathException
Resolve the XPath expression for the reference node. If no XPath expression is passed or no reference node is known a RuntimeException is thrown. This function always returns a NodeSet even if the result is not a NodeSet, in this last case this is always an empty NodeSet

XPathException

resolveAny

public java.lang.Object resolveAny()
                            throws XPathException
Resolve the XPath expression, user has to cast correctly the result as NodeSet, String, Double Boolean

XPathException

addNamespaceDeclaration

public void addNamespaceDeclaration(java.lang.String prefix,
                                    java.lang.String uri)
Add a namespace declaration If this prefix apperars in the XPath expression then the tied uri if used for discovering node from the uri namespace


removeNamespaceDeclaration

public void removeNamespaceDeclaration(java.lang.String prefix)
Remove a namespace declaration for this prefix


addVariable

public void addVariable(java.lang.String name,
                        int value)
Set a variable value from the XPath expression


addVariable

public void addVariable(java.lang.String name,
                        boolean value)
Set a variable value from the XPath expression


addVariable

public void addVariable(java.lang.String name,
                        double value)
Set a variable value from the XPath expression


addVariable

public void addVariable(java.lang.String name,
                        java.lang.String value)
Set a variable value from the XPath expression


addVariable

public void addVariable(java.lang.String name,
                        NodeSet value)
Set a variable value from the XPath expression


removeVariable

public void removeVariable(java.lang.String name)
Remove the variable binding for this name, if an XPath expression contains this name, an error will be thrown


setFeature

public void setFeature(java.lang.String feature,
                       boolean enable)
Set a feature support for the current kit. A RuntimeException should be thrown by the kit that doesn't support such feature


isFeatureSupported

public boolean isFeatureSupported(java.lang.String feature)
Returns:
true if the feature is supported by the current kit

getSupportedFeatures

public java.lang.String[] getSupportedFeatures()
Return a list of supported features by the current kit