List of utility methods to do XPath Expression
Map | createReverseCMDIComponentItemMap(String urlToComponent) Create a mapping out of simple CMDI components for instance: lists of items: Map<String, String> result = new HashMap<String, String>(); DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance(); domFactory.setNamespaceAware(true); URL url = new URL(urlToComponent); DocumentBuilder builder = domFactory.newDocumentBuilder(); Document doc = builder.parse(url.openStream()); XPath xpath = XPathFactory.newInstance().newXPath(); NodeList nodeList = (NodeList) xpath.evaluate("//item", doc, XPathConstants.NODESET); ... |
XPath | createXPath() Creates an XPath object with a custom NamespaceContext given the Node to operate on the Node or document to operate on. return XPathFactory.newInstance().newXPath();
|
XPath | createXPath(NamespaceContext namespaceContext, XPathFunctionResolver functionResolver) create X Path XPath xPath = XPathFactory.newInstance().newXPath(); if (namespaceContext != null) { xPath.setNamespaceContext(namespaceContext); if (functionResolver != null) { xPath.setXPathFunctionResolver(functionResolver); return xPath; ... |
XPathExpression | createXPathExpression(NamespaceContext context, String xPathQuery) create X Path Expression XPath xpath = XPathFactory.newInstance().newXPath();
xpath.setNamespaceContext(context);
return xpath.compile(xPathQuery);
|
XPathExpression | createXPathExpression(String expression, NamespaceContext namespaceContext) create X Path Expression XPath xpath = getFactory().newXPath(); if (namespaceContext != null) { xpath.setNamespaceContext(namespaceContext); XPathExpression expr = xpath.compile(expression); return expr; |
XPathExpression | createXPathExpression(String xpath) Create an XPathExpression from the supplied xpath string. if (XPATH == null) { XPATH = XPathFactory.newInstance().newXPath(); return XPATH.compile(xpath); |
XPathExpression | createXPathExpression(String xpathString) create X Path Expression XPathFactory factory = XPathFactory.newInstance(); XPath xpath = factory.newXPath(); xpath.setNamespaceContext(new NamespaceContext() { @Override public Iterator<?> getPrefixes(String namespaceURI) { throw new RuntimeException(); @Override ... |
String | deleteXMLElement(String xml, String xpath) delete XML Element try { final Node node = findXMLNode(xml, xpath); Node parent = node.getParentNode(); parent.removeChild(node); return XMLtoString(parent.getOwnerDocument()); } catch (XPathExpressionException e) { return null; |
void | dumpXpath(Node node, PrintStream printer) dump Xpath NodeList list = node.getChildNodes(); for (int i = 0; i < list.getLength(); i++) { Node item = list.item(i); printer.println("Xpath: " + getXPath(item)); printer.println("Text Content: " + item.getTextContent()); if (item.hasChildNodes()) { dumpXpath(item, printer); |
NodeList | executePath(final Node node, final XPathExpression expression) execute Path return (NodeList) expression.evaluate(node, XPathConstants.NODESET);
|