@Test public void testXPathWithValidatedDOMDocNamespace() throws Exception { LOG.debug("TEST"); Document doc = getDocument(true, true); LOG.info("Default namespace: " + doc.lookupNamespaceURI(null)); LOG.info("default prefix: " + doc.lookupPrefix(doc.lookupNamespaceURI(null))); XPath xpath = XPathFactory.newInstance().newXPath(); xpath.setNamespaceContext(Util.getNotificationNamespaceContext(doc)); String channelName = (String) xpath.evaluate( "/nreq:notification/nreq:channel", doc.getDocumentElement(), XPathConstants.STRING); assertEquals("Test Channel #1", channelName); }
private static Element createNode(Document doc, Element parentNode, String name) { Element newNode = doc.createElementNS(LayoutDeviceManager.LAYOUT_DEVICES_NAMESPACE, name); newNode.setPrefix(doc.lookupPrefix(LayoutDeviceManager.LAYOUT_DEVICES_NAMESPACE)); parentNode.appendChild(newNode); return newNode; }