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

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条回答 默认 最新

  • oyj7454103 2010-08-17 16:27
    关注

    如果你确定那个XML 能正常解析的话!

    [code="java"]InputStreamReader isr = new InputStreamReader(in,encoding); [/code]

    其他的编码试了么?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀