Refine search
/** * <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); }
public Object getValue(Object row) { switch (type) { case STRING_TYPE: return xpath.valueOf(row); case NUMBER_TYPE: return xpath.numberValueOf(row); case NODE_TYPE: return xpath.selectSingleNode(row); default: return xpath.evaluate(row); } }
@SuppressWarnings( "unchecked" ) private boolean applyXPath() { try { XPath xpath = data.document.createXPath( data.PathValue ); if ( meta.isNamespaceAware() ) { xpath = data.document.createXPath( addNSPrefix( data.PathValue, data.PathValue ) ); xpath.setNamespaceURIs( data.NAMESPACE ); } // get nodes list data.an = xpath.selectNodes( data.document ); data.nodesize = data.an.size(); data.nodenr = 0; } catch ( Exception e ) { logError( BaseMessages.getString( PKG, "GetXMLData.Log.ErrorApplyXPath", e.getMessage() ) ); return false; } return true; }
for (String exclude : excludes) { XPath xExclude = dom.createXPath(exclude); xExclude.setFunctionContext(functionContext); List<org.dom4j.Node> list = (List<org.dom4j.Node>)xExclude.selectNodes(dom); for (org.dom4j.Node n : list) { Element parent = n.getParent(); } else { XPath comp = dom.createXPath(xpath); comp.setFunctionContext(functionContext); List list = comp.selectNodes(dom);
/** * 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); }
public String getResponseParameter(String response) { if (!response2parameter.containsKey(response)) { String query = String.format("/xsd:schema/xsd:element[@name='%s']" + "/xsd:complexType/xsd:sequence" + "/xsd:element/@name", response); XPath xpath = DocumentHelper.createXPath(query); xpath.setNamespaceURIs(ns2prefix); String param = xpath.valueOf(getDocument()); if (param.isEmpty()) { param = null; } response2parameter.put(response, param); } return response2parameter.get(response); }
/** * 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); }
public List<Node> getRows() { if (rows == null) { rows = definition.getRowXPath().selectNodes(source); } return rows; }
/** * 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); }
xpathField.setNamespaceURIs( data.NAMESPACE ); if ( xmlDataField.getResultType() == GetXMLDataField.RESULT_TYPE_VALUE_OF ) { nodevalue = xpathField.valueOf( node ); } else { Node n = xpathField.selectSingleNode( node ); if ( n != null ) { nodevalue = n.asXML();
/** * <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); }
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); }
private ImmutableMap<String, PageProperty> extractDetails(String macroBodyXhtml) throws IOException, DocumentException, ParserConfigurationException, SAXException { final Document macroBodyDoc = getMacroBodyDocument(macroBodyXhtml); final XPath xpath = macroBodyDoc.createXPath(XPATH_TBODY); xpath.setNamespaceURIs(NAMESPACE_MAP); final ImmutableMap<String, PageProperty> emptyMap = ImmutableMap.of(); final Element tableElement = (Element) xpath.selectSingleNode(macroBodyDoc); if (tableElement == null) return emptyMap; @SuppressWarnings("unchecked") final List<Element> rowElements = tableElement.elements("tr"); if (rowElements == null) return emptyMap; return loadDetailPairsFromTableRows(rowElements); }
public Object loadConfig() throws ConfigurationException { XPath xpath = DocumentHelper.createXPath("/" + context.getName() + "/" + getPropertyName()); Element element = (Element) xpath.selectSingleNode(context); Map.Entry entry; Map map = new HashMap(); for (Iterator iterator = element.elementIterator(); iterator.hasNext();) { entry = (Map.Entry) getConfiguration().getConfigElement(Map.Entry.class, "property", (Element) iterator.next()); map.put(entry.getKey(), entry.getValue()); } return map; } }
private XPath createXPath(String xpathExpression) { XPath xpath = DocumentHelper.createXPath(xpathExpression); xpath.setNamespaceURIs(namespaces); return xpath; } }
protected XPath createColumnXPath(String expression) { XPath xpath = createXPath(expression); // associate my variable context xpath.setVariableContext(this); return xpath; }
public Node selectSingleNode(String xpathExpression) { XPath xpath = createXPath(xpathExpression); return xpath.selectSingleNode(this); }
public List<Node> selectNodes(Object context, org.dom4j.XPath sortXPath, boolean distinct) { List<Node> answer = selectNodes(context); sortXPath.sort(answer, distinct); return answer; }
private XPath createXPath( String xpathExpr ) { XPath xpath = document.createXPath( xpathExpr ); if ( !this.namespaceMap.isEmpty() ) { xpath.setNamespaceURIs( this.namespaceMap ); } return xpath; }