XML { protected static Node selectNode(String xpath, Object node) { Node domNode = getNode(node); if (domNode == null) { log.severe("Unable to select node for non DOM Node object"); return null; } try { xpath = getExpression(xpath); XPath xp = XPathFactory.newInstance().newXPath(); return (Node) xp.evaluate(xpath, domNode, XPathConstants.NODE); } catch (XPathExpressionException e) { log.log(Level.SEVERE, "Failed to select node for xpath '" + xpath + "'", e); } return null; }  static String serialize(Object node); static boolean predicate(String xpath, Object node); static String evaluate(String xpath, Object node);  }
@Test public void testSelectNodeOrder() { String xml = "<soapenv:Envelope xmlns:soapenv=\"http: + "xmlns:urn=\"urn:switchyard-quickstart-demo:orders:1.0\">\n <soapenv:Header/>\n" + "<soapenv:Body>\n <urn:submitOrder>\n <order>\n " + "<orderId>1</orderId>\n <itemId>BUTTER</itemId>\n " + "<quantity>100</quantity>\n <customer>Fred</customer>\n " + "</order>\n </urn:submitOrder>\n </soapenv:Body>\n</soapenv:Envelope>"; Node result = XML.selectNode("*[local-name() = 'Envelope']/*[local-name() = 'Body']" + "/*[local-name() = 'submitOrder']/order", xml); assertNotNull(result); assertEquals("order", result.getLocalName()); }
@Test public void testSelectNodeOrderWildcard() { String xml = "<soapenv:Envelope xmlns:soapenv=\"http: + "xmlns:urn=\"urn:switchyard-quickstart-demo:orders:1.0\">\n <soapenv:Header/>\n" + "<soapenv:Body>\n <urn:submitOrder>\n <order>\n " + "<orderId>1</orderId>\n <itemId>BUTTER</itemId>\n " + "<quantity>100</quantity>\n <customer>Fred</customer>\n " + "</order>\n </urn:submitOrder>\n </soapenv:Body>\n</soapenv:Envelope>"; Node result = XML.selectNode("*:Envelope/*:Body/*:submitOrder/order", xml); assertNotNull(result); assertEquals("order", result.getLocalName()); }