我解析服务器上的XML我读它并解析它没有任何错误但我无法看到数据。在android中解析CDATA
这里是我的XML:
<BookData><book><Title><![CDATA[ABC]]></Title><AuthorFName1><![CDATA[A]]></AuthorFName1><AuthorLName1><![CDATA[B]]></AuthorLName1></book><book><Title><![CDATA[XYZ]]></Title><AuthorFName1><![CDATA[A]]></AuthorFName1><AuthorLName1><![CDATA[B]]></AuthorLName1></book>
我使用DocumentBuilderFactory
看到连我设置
dbf.setCoalescing(true);
但仍无法正常工作,请参阅的DocumentBuilderFactory
Document doc = null;
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setCoalescing(true);
try {
DocumentBuilder db = dbf.newDocumentBuilder();
InputSource is = new InputSource();
is.setCharacterStream(new StringReader(xml));
doc = db.parse(is);
} catch (ParserConfigurationException e) {
Log.d("XML parse Error:", e.getMessage());
return null;
} catch (SAXException e) {
Log.d("Wrong XML File Structure", e.getMessage());
return null;
} catch (IOException e) {
Log.d("IOException", e.getMessage());
return null;
}
在StackOverflow上有很多类似的问题。 http://stackoverflow.com/search?q=parse+cdata+in+android –
请在这里更新你的xml,因为这个xml不是正确的。所以,所有未来的用户都可以从这个答案中获益。 –
更新.............. –