List of utility methods to do XPath Expression
XPathExpression | expr(String xpathStr) expr XPath xpath = factory.newXPath();
return xpath.compile(xpathStr);
|
String | extractNode(XPath xpath, String nodePath, String xmlString) Extract a String node from an XML Message InputSource inputSource = new InputSource(new StringReader(xmlString)); try { return (String) xpath.evaluate(nodePath, inputSource, XPathConstants.STRING); } catch (XPathExpressionException e) { return ""; |
NodeList | extractNodeList(XPath xpath, String nodePath, String xmlString) extract Node List InputSource inputSource = new InputSource(new StringReader(xmlString)); try { return (NodeList) xpath.evaluate(nodePath, inputSource, XPathConstants.NODESET); } catch (XPathExpressionException e) { return null; |
NodeList | extractNodes(File xmlFile, String xpathLocator) extract Nodes DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(xmlFile);
XPathFactory xPathfactory = XPathFactory.newInstance();
XPath xpath = xPathfactory.newXPath();
XPathExpression expr = xpath.compile(xpathLocator);
return (NodeList) expr.evaluate(doc, XPathConstants.NODESET);
|
String | extractValue(String xml, String xpathExpression) extract Value String actual; try { DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); documentBuilderFactory.setIgnoringElementContentWhitespace(true); DocumentBuilder docBuilder = documentBuilderFactory.newDocumentBuilder(); byte[] bytes = xml.getBytes("UTF-8"); InputStream inputStream = new ByteArrayInputStream(bytes); ... |
List | findElements(final String xPathExpression, final Element root) Checks in under a given root element whether it can find a child elements which match the XPath expression supplied. final List<Element> elements = new ArrayList<Element>(); NodeList nodes = null; try { XPathExpression expr = COMPILED_EXPRESSION_CACHE.get(xPathExpression); if (expr == null) { expr = XPATH.compile(xPathExpression); COMPILED_EXPRESSION_CACHE.put(xPathExpression, expr); nodes = (NodeList) expr.evaluate(root, XPathConstants.NODESET); } catch (final XPathExpressionException e) { throw new IllegalArgumentException("Unable evaluate xpath expression", e); for (int i = 0, n = nodes.getLength(); i < n; i++) { elements.add((Element) nodes.item(i)); return elements; |
boolean | hasAnimatedPng(ImageReader reader) has Animated Png if (!"png".equals(reader.getFormatName())) { return false; try { IIOMetadata metadata = reader.getImageMetadata(0); XPath xPath = XPathFactory.newInstance().newXPath(); for (String name : metadata.getMetadataFormatNames()) { Node root = metadata.getAsTree(name); ... |
void | isLegalXPath(final String xPath) is Legal X Path XPathFactory factory = XPathFactory.newInstance(); XPath xpath = factory.newXPath(); xpath.compile(xPath); |
boolean | isValidFilter(String xPathString) is Valid Filter if (xPathString == null) { return true; try { XPath xPath = xPathFactory.newXPath(); xPath.compile(xPathString); return true; } catch (XPathExpressionException ex) { ... |
boolean | isXPathAbsolute(String path) is X Path Absolute validateXPath(path);
return path.matches(REGEX_PATH_ABS);
|