public String getDocumentValueStr(String xpath, String pattern) { String s = ""; try { Dom4jXPath p = new Dom4jXPath(xpath); p.addNamespace("h", NamespaceStr); s = p.stringValueOf(doc); } catch (Exception e) { System.out.println(e.getMessage()); } if (s.length() > 0 && pattern.length() > 0) { Pattern p = Pattern.compile(pattern, Pattern.MULTILINE | Pattern.DOTALL | Pattern.UNICODE_CASE); Matcher m = p.matcher(s); if (m.find()) { s = m.group(1); } } return s.replaceAll("^[ \\s]+|\\s{2,}+|[ \\s]+$", ""); }
public List selectNodes(Node n, String XPathStr) throws Exception { Dom4jXPath p = new Dom4jXPath(XPathStr); p.addNamespace("h", NamespaceStr); return p.selectNodes(n); }
public Node selectSingleNode(Node n, String XPathStr) throws Exception { Dom4jXPath p = new Dom4jXPath(XPathStr); p.addNamespace("h", NamespaceStr); return (Node) p.selectSingleNode(n); }