List of usage examples for org.w3c.dom Document getNamespaceURI
public String getNamespaceURI();
null
if it is unspecified (see ). From source file:org.opennms.protocols.xml.collector.AbstractXmlCollectionHandler.java
/** * Gets the XML document./*w w w. java 2 s. com*/ * * @param is the input stream * @param request the request * @return the XML document * @throws Exception the exception */ protected Document getXmlDocument(InputStream is, Request request) throws Exception { is = preProcessHtml(request, is); is = applyXsltTransformation(request, is); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setIgnoringComments(true); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); StringWriter writer = new StringWriter(); IOUtils.copy(is, writer, "UTF-8"); String contents = writer.toString(); Document doc = builder.parse(IOUtils.toInputStream(contents, "UTF-8")); // Ugly hack to deal with DOM & XPath 1.0's battle royale // over handling namespaces without a prefix. if (doc.getNamespaceURI() != null && doc.getPrefix() == null) { factory.setNamespaceAware(false); builder = factory.newDocumentBuilder(); doc = builder.parse(IOUtils.toInputStream(contents, "UTF-8")); } return doc; }