I am trying to parse an xml using DocumentBuilder's parse method which takes URI as an argument. For this I create a String object representing the URI and then call the parse method passing the String object as the argument.
The parse method call works fine, returns a new DOM object. However, when I try to print the returned DOM object, it says: org.xml.sax.SAXParseException: The markup in the document following the root element must be well-formed. The code snippet for parsing the xml is as shown below:
String sURL="http://host:port/myapp/serv?arg=abc&arg2=def";
DocumentBuilder dBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
doc = dBuilder.parse(sURL);
When I manually try accessing the URL in a browser it works fine, i.e it returns the xml.
The xml that the url returns is well formed.
The parse method when called as shown above doesn't throw any exception, however the DOM object tells about org.xml.sax.SAXParseException
Below is the stacktrace of the exception:
org.xml.sax.SAXParseException: The markup in the document following the root element must be well-formed. at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source) at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(Unknown Source) at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source) at com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(Unknown Source) at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$TrailingMiscDriver.next(Unknown Source) at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source) at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source) at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source) at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source) at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source) at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown Source) at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unknown Source) at javax.xml.parsers.DocumentBuilder.parse(Unknown Source) at DocBuilderTest.getDocumentFromURL(DocBuilderTest.java:103) at DocBuilderTest.main(DocBuilderTest.java:54)
Any help on this will be highly appreciated.
Thanks.