xsmeral.semnet.util
Class XPathUtil

java.lang.Object
  extended by xsmeral.semnet.util.XPathUtil

public class XPathUtil
extends Object

Utility class for scrapers, simplifies XPath querying. It is dependent on the HtmlCleaner API.

See Also:
AbstractScraper

Constructor Summary
XPathUtil()
           
 
Method Summary
static String getText(Object node)
          Returns text content of a node.
static List<TagNode> queryNodes(TagNode node, String xpath)
          Queries the supplied node with the supplied XPath expression and returns list of matching nodes
static String queryText(TagNode node, String xpath)
          Queries the supplied node with the supplied XPath expression and returns the text content.
static List<String> queryTextNodes(TagNode node, String xpath)
          Queries the supplied node with the supplied XPath expression and returns list of text contents of the matched nodes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XPathUtil

public XPathUtil()
Method Detail

getText

public static String getText(Object node)
Returns text content of a node. The node can be a String, a TagNode or a ContentNode. In case of a TagNode, the first child of the node is returned. The result is trimmed.

Parameters:
node - The node (a String, TagNode or ContentNode)
Returns:
Text content of the node trimmed, or null
See Also:
String.trim()

queryText

public static String queryText(TagNode node,
                               String xpath)
                        throws XPatherException
Queries the supplied node with the supplied XPath expression and returns the text content.

Parameters:
node - The node to query
xpath - The query
Returns:
Text content of the matched node, or null
Throws:
XPatherException

queryTextNodes

public static List<String> queryTextNodes(TagNode node,
                                          String xpath)
                                   throws XPatherException
Queries the supplied node with the supplied XPath expression and returns list of text contents of the matched nodes.

Parameters:
node - The node to query
xpath - The query
Returns:
List of text contents of the matched nodes, or an empty list
Throws:
XPatherException

queryNodes

public static List<TagNode> queryNodes(TagNode node,
                                       String xpath)
                                throws XPatherException
Queries the supplied node with the supplied XPath expression and returns list of matching nodes

Parameters:
node - The node to query
xpath - The query
Returns:
List of matching nodes
Throws:
XPatherException