lenj520
2010-08-17 15:49
浏览 179
已采纳

HttpURLConnection抓取页面资源问题

public class XML {

public Document getDoc(String u, String encoding) {
Document doc = null;
try {
URL url = new URL(u);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.connect();
DocumentBuilder dombuilder = builderFactory.newDocumentBuilder();
InputStream in = new BufferedInputStream(conn.getInputStream());
InputStreamReader isr = new InputStreamReader(in,encoding);
InputSource inputSource = new InputSource(isr);

[color=darkred]doc = dombuilder.parse(inputSource);[/color]
} catch (Exception e) {
e.printStackTrace();
}
return doc;
}
public static void main(String[] args) {

XML x=new XML();
String u = "http://www.p5w.net/stock/hydx/bkfx/index_160.xml";
x.getDoc(u,"utf-8");
}

}
出如下异常 一直无法解决 高手帮下忙 谢谢了
[Fatal Error] :206:35: An invalid XML character (Unicode: 0xdf2f) was found in the element content of the document.
org.xml.sax.SAXParseException: An invalid XML character (Unicode: 0xdf2f) was found in the element content of the document.
at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source)
at com.util.XML.getDoc(XML.java:117)(红色部分)
at com.util.XML.main(XML.java:134)

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

4条回答 默认 最新

相关推荐 更多相似问题