How can I create Document from a String containing XML?
I've tried the following code, but the document.getElementsByTagNameNS("Envelope", "http://schemas.xmlsoap.org/soap/envelope/") function call does not find any XML element.
String xml = "<soapenv:Envelope\n" +
" xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\">\n" +
"\t<soapenv:Header>\n" +
"\t</soapenv:Header>\n" +
"\t<soapenv:Body>\n" +
"\t</soapenv:Body>\n" +
"</soapenv:Envelope>";
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder;
try {
factory.setNamespaceAware(true);
builder = factory.newDocumentBuilder();
Document document = builder.parse(new InputSource(new StringReader(xml)));
System.out.println(document.getElementsByTagNameNS("Envelope", "http://schemas.xmlsoap.org/soap/envelope/").getLength());
} catch (Exception e) {
e.printStackTrace();
}