我有一个本地 xml 文件。我在这里存储:res/xml/myxml.xml
<?xml version="1.0" encoding="utf-8"?>
<list>
<lists>
<tag>College Website</tag>
<value>http://www.nitk.ac.in/</value>
<lastupdate>04-07-2012</lastupdate>
</lists>
<lists>
<tag>College Images</tag>
<value>http://studentsworld.nitk.ac.in/index.php?q=convocation.html</value>
<lastupdate>25-9-2011</lastupdate>
</lists>
</list>
我有循环文档。但是如何在文档解析器中连接本地 xml 文件。我不想要 url 模型,我想要一个本地 xml 文件。
for (int i = 0; i < nodeList.getLength(); i++) {
Node node = nodeList.item(i);
tag[i] = new TextView(this);
value[i] = new TextView(this);
lastupdate[i] = new TextView(this);
Element fstElmnt = (Element) node;
NodeList nameList = fstElmnt.getElementsByTagName("tag");
Element nameElement = (Element) nameList.item(0);
nameList = nameElement.getChildNodes();
tag[i].setText("tag = " + ((Node) nameList.item(0)).getNodeValue());
NodeList websiteList = fstElmnt.getElementsByTagName("value");
Element websiteElement = (Element) websiteList.item(0);
websiteList = websiteElement.getChildNodes();
value[i].setText("value = " + ((Node) websiteList.item(0)).getNodeValue());
NodeList lastupdateList = fstElmnt.getElementsByTagName("tag");
Element lastupdateElement = (Element) lastupdateList.item(0);
lastupdateList = lastupdateElement.getChildNodes();
lastupdate[i].setText("lastupdate = " + ((Node) lastupdateList.item(0)).getNodeValue());
layout.addView(tag[i]);
layout.addView(value[i]);
layout.addView(lastupdate[i]);
}
} catch (Exception e) {
System.out.println("XML Pasing Excpetion = " + e);
}
我有 main.xml 文件,请给我一个代码