我是 XML 解析的新手。我正在尝试访问“I Heart Quotes” API。这是产生错误的一段代码:
String link = "http://www.iheartquotes.com/api/v1/random.xml";
URL url = new URL(link);
InputStream is = url.openStream();
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(is);`
这是错误:
Content is not allowed in prolog.
org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Content is not allowed in prolog.
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:256) at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:345)
at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:121)
at com.nicolasekhoury.IHQuotes.IHQuotes.main(IHQuotes.java:28)
我应该怎么办?