## org.opencyc.xml
Class XpathComputer

    java.lang.Object
      |
      +--org.opencyc.xml.XpathComputer

public class XpathComputer
extends java.lang.Object

Implements static methods for computing Xpath strings (www.w3.org/TR/xpath) for DOM Nodes (www.w3.org/DOM/)

Author:
  Stefano Bertolo

  Copyright 2001 Cycorp, Inc., license is open source GNU LGPL.

  the license

  www.opencyc.org

  OpenCyc at SourceForge

  THIS SOFTWARE AND KNOWLEDGE BASE CONTENT ARE PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OPENCYC ORGANIZATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE AND KNOWLEDGE BASE CONTENT, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Constructor Summary
`XpathComputer()`

Method Summary
`static java.lang.String` `computeXpath(org.w3c.dom.Node node)` Returns the entire Xpath string for the input node, i.e.
`static org.w3c.dom.Node` `followLocalXpath(org.w3c.dom.Node start, java.lang.String localXpath)` Takes a starting DOM node and a local Xpath directive and returns the DOM node, if any, which can be reached following the directive from the input node It throws DOMExceptions if no node exists at the specified address or if the address is not a valid local Xpath expression.
`static org.w3c.dom.Node` `followXpath(org.w3c.dom.Node start, java.lang.String Xpath)` Takes a starting DOM node and an Xpath directive and returns the DOM node, if any, which can be reached following the directive from the input node.
`static java.lang.String` `localXpath(org.w3c.dom.Node node)` Returns the local Xpath string for the input node, i.e.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### XpathComputer

    public XpathComputer()

Method Detail

### localXpath

    public static java.lang.String localXpath(org.w3c.dom.Node node)
                                       throws org.w3c.dom.DOMException

  Returns the local Xpath string for the input node, i.e. the Xpath string one would need to reach the node from its parent. For example, if node is the DOM node corresponding to the node <twig> <leaf>a</leaf> <leaf>friend</leaf> </twig> in the tree above, XpathComputer.localXpath(node) would return "/twig[2]"
  Returns:
    the local Xpath string for the input node.
  Throws:
    `throws` - DOMException.

### followLocalXpath

    public static org.w3c.dom.Node followLocalXpath(org.w3c.dom.Node start,
                                                    java.lang.String localXpath)
                                             throws org.w3c.dom.DOMException

  Takes a starting DOM node and a local Xpath directive and returns the DOM node, if any, which can be reached following the directive from the input node It throws DOMExceptions if no node exists at the specified address or if the address is not a valid local Xpath expression. We repeat here that this is a very limited implementation of Xpath addressing which is guaranteed to handle all and *only* those Xpath expressions that could have been the output of the XpathComputer.localXpath method For example, if start is the DOM node corresponding to the node <twig> <leaf>a</leaf> <leaf>friend</leaf> </twig> in the tree above, XpathComputer.followLocalXpath(start, "leaf[2]") would return the node <leaf>friend</leaf>
  Returns:
    the DOM node that is reached following the input Xpath directiv starting from the input node.
  Throws:
    `throws` - DOMException.

### computeXpath

    public static java.lang.String computeXpath(org.w3c.dom.Node node)

  Returns the entire Xpath string for the input node, i.e. the Xpath string one would need to reach the node from the root of the document. For example, if node is the DOM node corresponding to the node <leaf>friend</leaf> in the tree above, XpathComputer.computeXpath(node) would return "/tree[1]/branch[2]/twig[2]/leaf[2]"
  Returns:
    the entire Xpath string for the input node.

### followXpath

    public static org.w3c.dom.Node followXpath(org.w3c.dom.Node start,
                                               java.lang.String Xpath)
                                        throws org.w3c.dom.DOMException

  Takes a starting DOM node and an Xpath directive and returns the DOM node, if any, which can be reached following the directive from the input node. It throws DOMExceptions if no node exists at the specified address or if the address is not a valid Xpath expression. We repeat here that this is a very limited implementation of Xpath addressing which is guaranteed to handle all and *only* those Xpath expressions that could have been the output of the XpathComputer.computeXpath method For example, if start is the DOM node corresponding to the root node in the tree above XpathComputer.follow.LocalXpath(start, "/tree[1]/branch[3]/twig[1]leaf[2]") would return the node <leaf>Sunday</leaf>
  Returns:
    the DOM node that is reached following the input Xpath directive starting from the input node.
  Throws:
    `throws` - DOMException.