Java tutorial
//package com.java2s; //License from project: Open Source License import java.io.StringReader; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import org.w3c.dom.Document; import org.xml.sax.InputSource; public class Main { /** * Parsing xml doc text as w3c dom * * @param xmlString xml doc as string * @return W3C DOM */ public static Document parseNSAware(String xmlString) { try { InputSource xmlInputSource = new InputSource(new StringReader(xmlString)); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); dbFactory.setNamespaceAware(true); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); return dBuilder.parse(xmlInputSource); } catch (Exception ex) { throw new RuntimeException("Error when parsing Xml doc", ex); } } }