To set the scene, I’m currently working on an XML adapter for Android that will read in the XML files I’ve been given and parse them into a database. I thought I had this down until they sprung on me that the nodes in the XML file could change from file to file, and so I need to build in a mechanism to cope with missing variables.
The most obvious solution to this was a switch() statement, but that won’t work with strings, so I started building an if-then-else structure. The idea was that it would check the name of the node and work out what to do with it based on that. Simple, no?
The problem is, I can’t seem to pull the name of the nodes I need from the XML file no matter what I do. The structure of the XML file is below:
<Vehicle>
<Detail>
<VIN>BBB2791276393</VIN>
<RegNo>KN05EAP</RegNo>
<Doors>5</Doors>
</Detail>
</Vehicle>
What I need to be able to compare against is tag names like “VIN” or “RegNo”, but I can’t figure out a way to pull them out. ETA: As I didn’t make this clear, the child nodes of Detail change between XML files, and I have to deal with them as they come…
I’m using a DOM parser, and pulling out a NodeList based on <Detail>. NodeList.item(0) gives me the <Detail> node, but if I then try and break that down (with getChildNodes() for example), I can’t get the tag names for <VIN> or <RegNo>. In fact, I can’t seem to get any kind of reference for them that I could use to determine what node it is based on the original name.
Anyone got any ideas?
Ok..as you explained that you can reach up to Detail tag..try doing it this way…
You can do it for all the children tags of Detail…Hope this will help you..!!!