I hate to just leave this here, but I answered a similar question here.
In Java you have quite a few options on actually parsing the XML - XPath will be the slowest but gives you a nice expression language to query the content with. DOM will be the second slowest but give you a tree-model in memory of your doc to walk. SAX will be faster, but requires you build the list as it parses through the doc on the fly and lastly STAX will be the fastest, but requires that you write some specific code to your format to build your list out.
Lastly, I would recommend a library I wrote called SJXP that gives you the performance of STAX with the ease of XPath... it is the perfect blend of the two.
You write rules like "/root/Persons/list/Person/Name" and give it your doc and it will fire every time it hits a name and call a user-provided callback for you, handing you the name it found.
You create a few rules for all the values you want and viola... you can create a START_TAG rule for the "/root/Persons/list/Person" open-tag, and create a new "Person p = new Person()" in your code, then as every sub-element hits, you just set the appropriate value on the person, something like this (as an example):
IRule linkRule = new DefaultRule(Type.CHARACTER, "/root/Persons/list/Person/Name") {
@Override
public void handleParsedCharacters(XMLParser parser, String text, Object userObject) {
// Get the last person we added on open-tag.
Person p = personList.get(personList.size() - 1);
// <Name> tag was parsed, 'text' is our parsed Name. Set it.
p.setName(text);
}
}
The nice thing about SJXP is that the memory overhead is lower than the other parser approaches and performance higher (SAX will parse the elements on a match, STAX-based parsing doesn't parse the elements out of the stream until they are requested).
You will end up writing equally confusing code just to traverse your DOM and all the Node elements to build your list.
LASTLY, if you felt comfortable with XML->Object mapping, you could do what another person said and leverage JAXB. You will need to write a schema for your XML files, then it will generate Java objects for you that map perfect to them. Then you can just map your XML file directly to your Java object and call something like "persons.getList()" or whatever JAXB generates for you.
The memory overhead and performance will be on par with DOM parsing in that case (roughly).