se.kb.xml
Class XPathWrapper

java.lang.Object
  extended by se.kb.xml.XPathWrapper

public class XPathWrapper
extends Object

Helper class that eases the job of handling XPath queries and getting the different results. It wraps a Node and then performs the XPath queries on that.

Author:
Oskar Grenholm, National Library of Sweden

Constructor Summary
XPathWrapper(Node node)
          Wraps a Node for easier XPath handling.
XPathWrapper(Node node, Map<String,String> namespaces)
          Creates a XPathWrapper that should be aware of all the namespaces in the Map when handling XPath queries.
 
Method Summary
 void addNamespace(String prefix, String uri)
          Adds a namespace that the wrapper should be aware of when performing XPath queries.
 List<Node> selectNodes(String xpathExpression)
          Selects all Nodes that matches the given XPath.
 Element selectSingleElement(String xpathExpression)
          Selects a single result that matches the given XPath and then casts it into a Element.
 Node selectSingleNode(String xpathExpression)
          Selects a single node that matches the given XPath.
 String valueOf(String xpathExpression)
          Selects the value of the given XPath.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XPathWrapper

public XPathWrapper(Node node)
Wraps a Node for easier XPath handling.

Parameters:
node - the Node to wrap

XPathWrapper

public XPathWrapper(Node node,
                    Map<String,String> namespaces)
Creates a XPathWrapper that should be aware of all the namespaces in the Map when handling XPath queries.

Parameters:
node - the Node to wrap
namespaces - the namespaces
Method Detail

addNamespace

public void addNamespace(String prefix,
                         String uri)
Adds a namespace that the wrapper should be aware of when performing XPath queries.

Parameters:
prefix - the prefix of the namespace
uri - the uri of the namespace

selectSingleNode

public Node selectSingleNode(String xpathExpression)
Selects a single node that matches the given XPath.

Parameters:
xpathExpression - the xpath
Returns:
a single Node or null if no match

selectNodes

public List<Node> selectNodes(String xpathExpression)
Selects all Nodes that matches the given XPath.

Parameters:
xpathExpression - the xpath
Returns:
a list of nodes (can be empty if no matches)

selectSingleElement

public Element selectSingleElement(String xpathExpression)
Selects a single result that matches the given XPath and then casts it into a Element.

Parameters:
xpathExpression - the xpath
Returns:
a single Element or null if no match

valueOf

public String valueOf(String xpathExpression)
Selects the value of the given XPath.

Parameters:
xpathExpression - the xpath
Returns:
the value or null if no match


Copyright © 2008. All Rights Reserved.