I have one local xml file. I am storing here : 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>
I have doc for loop. but how to connect local xml file in doc parser. i don’t want url model, i want to a local xml file.
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);
}
I have main.xml file
please send me a code
put you XML file in assets folder and try this
InputStream raw = getApplicationContext().getAssets().open("simple.xml");and try this