在我的應用程序中,我使用DOM解析器來解析XML。 DOM解析器通過在URL字符串中使用沒有任何空間的方式提供100%的結果。如果我的URL字符串中有任何空白,我會收到錯誤,如org.xml.sax.SAXParseException:意外的文檔結尾 這是我的網址字符串 「www.someurl.com/queryType=new-celeb&name=ABC&category=American Foot ball
」。 在上面的url字符串中有空格(美式足球)在category屬性中,所以我收到異常。沒有空白的工作。Android中的DOM Parser問題?
這是我的一段代碼
URL url= new URL("www.someurl.com/queryType=new-celeb&name=ABC&category=American Foot ball");
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(new InputSource(url.openStream()));
doc.getDocumentElement().normalize();
Element ele=doc.getDocumentElement();
NodeList nodeList = ele.getElementsByTagName("items");
給我一些想法,以解決我的問題。