Exactly what do you want to do with "java hashmap/objects" after you get them? Are you talking about creating one or many objects? You need to expand your description of the problem before you can get more detailed help. It may well be that the standard Java xml library has all you need but we cant tell at this point.
Then you don't really need a hash map, right? A structured Java object containing those fields would work better. In this case you want one of the Java-XML binding tools like JAXB or Castor (or quite a few others).
Author and all-around good cowpoke
Joined: Mar 22, 2000
Here is how I tackled a similar problem (using your xml names for example.)
Assuming this is the basic item: <unit id="dgs">...etc </unit>
1. With DOM in memory, I get a NodeList of all elements named "unit" 2. Iterating through the nodelist - for each unit Element, get the id attribute value. 3. Store the Element in a Hashmap with the id value as key.
Now you can look up the Element by id and do further retrieval of values that are children of the Element. This uses the Element object that the parser creates rather than a separate Java object.
The Java API contains lots of tools for locating and pulling values out of XML objects, you might find it convenient to use XPath (javax.xml.xpath package) in Java 1.5. You could even use XPath directly on the DOM and never mess with Hashmaps at all.