how to revise xml parser exception "<?xml ... ?> prolog must be at the document start"
i use follows code to get a XML Document (by JDOM in java):
SAXBuilder builder = new SAXBuilder();
Document doc= builder.build(new URL("http://www.sasatuan.com/api/api.php"));
and i get a Exception:
org.jdom.input.JDOMParseException: Error in building:
http://www.sasatuan.com/api/api.php:1: <?xml ... ?> occurs after content. The
<?xml ... ?> prolog must be at the document start.: http://www.sasatuan.com/api/
api.php:1: <?xml ... ?> occurs after content. The <?xml ... ?> prolog must be a
t the document start.
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:473)
...
i type this URL http://www.sasatuan.com/api/api.php
in IE,it's be ok,but in firefox or chrome,it's same error.
this xml header not 开发者_如何学运维at the document start,so jdom can't read it.
i think trim() the xml content before build can revise this problem, i want know how to do this.
thanks for help :)
Do you have other XML files which are similarly broken that you need to read? If not, I would personally try to get in touch with the owner of the website. That XML is simply invalid - and it would probably be an easy job to fix it, which would help everyone rather than just you.
If that doesn't appeal, it would probably be easiest to download the content as a string, trim it in memory, and then load it. You could mess around trying to skip the relevant bits of the input stream, but that's more likely to be fiddly.
精彩评论