我试图将this XML解析到我的Android应用程序中。 我在这里读了很多关于在stackoverflow上解析XML的问题,但我不确定如何处理每个人提到的for
循环,就我而言。将XML解析为Android应用程序
如果有人愿意给我一个这个XML案例的实例,我会非常感激。
示例代码我发现计算器
try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(*/Insert my URL/*);
doc.getDocumentElement().normalize();
NodeList nodeList = doc.getElementsByTagName(*/What to write here in my case?/*);
item = new TextView[nodeList.getLength()];
for (int i = 0; i < nodeList.getLength(); i++) {
Node node = nodeList.item(i);
item[i] = new TextView(this);
Element fstElmnt = (Element) node;
NodeList itemList = fstElmnt.getElementsByTagName(*/What to write here in my case?/*);
Element itemElement = (Element) itemList.item(0);
itemList = itemElement.getChildNodes();
item[i].setText("item = "
+ ((Node) itemList.item(0)).getNodeValue());
layout.addView(item[i]);
}
}
catch (Exception e) {
System.out.println("XML Pasing Excpetion = " + e);
}
/** Set the layout view to display */
setContentView(layout);
}
上面的代码是NOT,我使用的例子。这正是我在互联网上发现的如何在Android应用上解析XML。但是,我的XML似乎比这里的贴子更复杂。
你能不能给我一个链接或一个简短的解释,我怎么会在这里使用JSON? 我知道JSON是什么,因为我使用它。但是现在它让我困惑,因为我不知道如何使用JSON在我的应用程序上显示该XML。 – user3533253 2014-10-08 16:20:12
你不能在这里使用JSON,我的错误。这里是一个指南,看起来很容易遵循 - http://www.mkyong.com/java/how-to-read-xml-file-in-java-dom-parser/ – apmartin1991 2014-10-08 16:22:43