org.xml.sax.SAXParseException:[color=#33CCCC][/color] URL url = new URL("http://www.webxml.com.cn/WebServices/WeatherWebService.asmx");
Document doc;
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
InputStream is = url.openStream();
doc = db.parse(is);
异常信息[Fatal Error] :46:295: The element type "p" must be terminated by the matching end-tag "</p>".
org.xml.sax.SAXParseException: The element type "p" must be terminated by the matching end-tag "</p>".
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:239)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:283)
at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:124)
at UrlContext2.main(UrlContext2.java:19)
------解决方案--------------------楼主你想问的是怎么解决这个错误么??
貌似类型转换出错了
------解决方案--------------------Html是弱格式化语言,而不是标准xml格式。你可以把获取的数据全部打印出来,看是否有不符合xml格式的地方。
BufferedReader br=new BufferedReader( new InputStreamReader(url.openStream()));
String text;
while((text=br.readLine())!=null){
System.out.println(text);
}