Im having a hard time trying to figure out how to parse this block of data:
<prov version="1.1">
<characteristic type="section1">
<parm name="version" value="74"/>
<parm name="validity" value="172800"/>
</characteristic>
...
<characteristic type="section99">
<parm name="random_setting1" value="blahblah1"/>
<parm name="random_setting2" value="blahblah2"/>
<characteristic type="section99_subsection2">
<parm name="random_setting3" value="blahblah1"/>
<parm name="random_setting4" value="blahblah2"/>
</characteristic>
</characteristic>
</prov>
I have probably 200+ lines in an xml file resembling the above example. Id like to break it up into 4 fields to put in a database:
1stlevel characteristic
2ndlevel characteristic (can be null)
settingName
value
But I cannot for the life of me figure out how to do this.
I have this document builder:
Log.d("RNM", "Starting xmlToDb");
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document xmlParse = dBuilder.parse(new InputSource(new StringReader(xmlString)));
xmlParse.getDocumentElement().normalize();
NodeList nList = xmlParse.getElementsByTagName("characteristic");
for ( int tmp = 0; tmp < nList.getLength(); tmp++) {
Node nNode = nList.item(tmp);
System.out.println("\nCurrent Element :" + nNode.getNodeName());
if ( nNode.getNodeType() == Node.ELEMENT_NODE) {
Element eElement = (Element) nNode;
String charType = eElement.getAttribute("type"); //Tells me the value of characteristic
}
}
The above works to pull out all the characteristic blocks and can get the values. but I can't figure out how to extract the parmName and parmValud that lie beneath each one.
Any examples out there on dealing with this? I looked here: http://theopentutorials.com/tutorials/android/xml/android-simple-xml-sax-parser-tutorial/ But I could not figure out how to grab those values with the saxparser.