protected XPath createXPath(String expression) { return DocumentHelper.createXPath(expression); }
protected XPath createXPath(String expression) { return DocumentHelper.createXPath(expression); }
/** * <p> * <code>sort</code> sorts the given List of Nodes using an XPath * expression as a {@link java.util.Comparator}. * </p> * * @param list * is the list of Nodes to sort * @param xpathExpression * is the XPath expression used for comparison */ public static void sort(List<Node> list, String xpathExpression) { XPath xpath = createXPath(xpathExpression); xpath.sort(list); }
/** * <p> * <code>selectNodes</code> performs the given XPath expression on the * {@link List}of {@link Node}instances appending all the results together * into a single list. * </p> * * @param xpathFilterExpression * is the XPath filter expression to evaluate * @param nodes * is the list of nodes on which to evalute the XPath * * @return the results of all the XPath evaluations as a single list */ public static List<Node> selectNodes(String xpathFilterExpression, List<Node> nodes) { XPath xpath = createXPath(xpathFilterExpression); return xpath.selectNodes(nodes); }
/** * <p> * <code>selectNodes</code> performs the given XPath expression on the * {@link List}of {@link Node}instances appending all the results together * into a single list. * </p> * * @param xpathFilterExpression * is the XPath filter expression to evaluate * @param node * is the Node on which to evalute the XPath * * @return the results of all the XPath evaluations as a single list */ public static List<Node> selectNodes(String xpathFilterExpression, Node node) { XPath xpath = createXPath(xpathFilterExpression); return xpath.selectNodes(node); }
/** * <p> * <code>sort</code> sorts the given List of Nodes using an XPath * expression as a {@link java.util.Comparator}and optionally removing * duplicates. * </p> * * @param list * is the list of Nodes to sort * @param expression * is the XPath expression used for comparison * @param distinct * if true then duplicate values (using the sortXPath for * comparisions) will be removed from the List */ public static void sort(List<Node> list, String expression, boolean distinct) { XPath xpath = createXPath(expression); xpath.sort(list, distinct); }
protected XPath createXPath(String expression) { return DocumentHelper.createXPath(expression); }
protected XPath createXPath(String expression) { return DocumentHelper.createXPath(expression); }
private XPath createXPath(String xpathExpression) { XPath xpath = DocumentHelper.createXPath(xpathExpression); xpath.setNamespaceURIs(namespaces); return xpath; } }
private static String first(Document doc, String selector) { XPath xpath = DocumentHelper.createXPath(selector); try { return Iterables.get((List<Element>) xpath.selectNodes(doc), 0).getText(); } catch (IndexOutOfBoundsException e) { throw new RuntimeException("Malformed response for " + selector + " in " + doc.asXML()); } }
private static String first(Document doc, String selector) { XPath xpath = DocumentHelper.createXPath(selector); try { return Iterables.get((List<Element>) xpath.selectNodes(doc), 0).getText(); } catch (IndexOutOfBoundsException e) { throw new RuntimeException("Malformed response for " + selector + " in " + doc.asXML()); } }
private XPath createXPath(String xpathExpr) { HashMap<String, String> namespaceURIMap = new HashMap<String, String>(); namespaceURIMap.put("masc", "http://www.xces.org/ns/GrAF/1.0/"); XPath path = DocumentHelper.createXPath(xpathExpr); path.setNamespaceContext(new SimpleNamespaceContext(namespaceURIMap)); return path; }
private boolean dependencyHasMatchingGroupId(Element parentDependency) { XPath xpathGroupIdSelector = DocumentHelper.createXPath("./mvn4:groupId[text()=\"" + groupId + "\"]"); xpathGroupIdSelector.setNamespaceURIs(namespaceUris); return !xpathGroupIdSelector.selectNodes(parentDependency).isEmpty(); }
/** * Executes the specified namespace aware XPath query as a multiple node query, returning the resulting list of nodes. */ @SuppressWarnings("unchecked") public static List<Node> selectNodes(Node node, String xpathQuery, Map<String, String> namespaceUris) { XPath xpath = DocumentHelper.createXPath(xpathQuery); xpath.setNamespaceURIs(namespaceUris); return xpath.selectNodes(node); }
/** * Executes the specified namespace aware XPath query as a single node query, returning the resulting single node. */ public static Node selectSingleNode(Node node, String xpathQuery, Map<String, String> namespaceUris) { XPath xpath = DocumentHelper.createXPath(xpathQuery); xpath.setNamespaceURIs(namespaceUris); return xpath.selectSingleNode(node); }
private void convertDefaultPriceModes(final Document doc) { XPath xpathSelector = DocumentHelper.createXPath("/settings/marketstat"); List<?> results = xpathSelector.selectNodes(doc); for (Iterator<?> iter = results.iterator(); iter.hasNext();) { Element elem = (Element) iter.next(); Attribute attr = elem.attribute("defaultprice"); if (attr != null) { //May not exist (in early versions) String currentValue = attr.getText(); attr.setText(convertDefaultPriceMode(currentValue)); } } }
private void convertModes(final Document doc) { XPath xpathSelector = DocumentHelper.createXPath("/settings/filters/filter/row"); List<?> results = xpathSelector.selectNodes(doc); for (Iterator<?> iter = results.iterator(); iter.hasNext();) { Element elem = (Element) iter.next(); Attribute attr = elem.attribute("mode"); String currentValue = attr.getText(); attr.setText(convertMode(currentValue)); } }
/** * A bug found by Stefan which results in IndexOutOfBoundsException for * empty results * * @throws Exception * DOCUMENT ME! */ public void testStefan() throws Exception { String text = "<foo>hello</foo>"; Document document = DocumentHelper.parseText(text); XPath xpath = DocumentHelper.createXPath("/x"); Object value = xpath.evaluate(document); }
protected void testXPath(String xpathExpression) { XPath xpath = DocumentHelper.createXPath(xpathExpression); assertTrue("No xpath object was created", xpath != null); log("Evaluating xpath: " + xpath); List list = document.selectNodes("//author"); for (Iterator iter = list.iterator(); iter.hasNext();) { Node node = (Node) iter.next(); testXPath(node, xpath); } }
protected void testXPath(String xpathText) { XPath xpath = DocumentHelper.createXPath(xpathText); SimpleNamespaceContext context = new SimpleNamespaceContext(); context.addNamespace("xplt", "www.xxxx.com"); context.addNamespace("xpl", "www.xxxx.com"); xpath.setNamespaceContext(context); List list = xpath.selectNodes(document); log("Searched path: " + xpathText + " found: " + list.size() + " result(s)"); assertTrue("Should have found at lest one result", list.size() > 0); }