转换包含Android development
的{{1}}时,我在XML to JSON
中遇到此错误。它在正常CDATA tag
中工作正常。
我使用过Java
。
Library
。
org.json
我已获得此类 public Document fetchXMLHTTP(String httpUrl) {
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setIgnoringComments(true);
factory.setCoalescing(true); // This removes CDATA Tag and converts it ", this doesn't work in Android
Log.v("xml_parser", "Coalescing Aware: " + factory.isCoalescing());
if(factory.isNamespaceAware()){
}
DocumentBuilder builder = factory.newDocumentBuilder();
URL uri = new URL(httpUrl);
Document doc = builder.parse(new InputSource(uri.openStream()));
doc.normalizeDocument();
NodeList xml = doc.getElementsByTagName("avatar");
Log.v("xml_parser", "Avatar Content: " + xml.item(0).getTextContent());
return doc;
} catch (Exception e) {
e.getStackTrace();
}
return null;
}
public String generateNewXML(Document doc, String tag) {
try {
NodeList xml = doc.getElementsByTagName(tag);
StringWriter sw = new StringWriter();
Transformer serializer = TransformerFactory.newInstance().newTransformer();
serializer.transform(new DOMSource(xml.item(0)), new StreamResult(sw));
String newXML = sw.toString();
System.out.println("New XML: " + newXML);
return newXML;
} catch (Exception e) {
e.getStackTrace();
}
return "";
}
。
Error
XML有两种类型java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:299)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
at java.util.concurrent.FutureTask.run(FutureTask.java:239)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
at java.lang.Thread.run(Thread.java:856)
Caused by: java.lang.NoSuchMethodError: org.json.XMLTokener.end
at org.json.XMLTokener.nextCDATA(XMLTokener.java:69)
at org.json.XML.parse(XML.java:165)
at org.json.XML.parse(XML.java:272)
at org.json.XML.parse(XML.java:272)
at org.json.XML.toJSONObject(XML.java:369)
at com.fragdeluxestats.model.DataHandler.getPlayerSummary(DataHandler.java:85)
at com.fragdeluxestats.model.DataAsyncTask.doInBackground(DataAsyncTask.java:45)
at com.fragdeluxestats.model.DataAsyncTask.doInBackground(DataAsyncTask.java:19)
at android.os.AsyncTask$2.call(AsyncTask.java:287)
at java.util.concurrent.FutureTask.run(FutureTask.java:234)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
at java.lang.Thread.run(Thread.java:856)
,如下所示:
tags