Sort Java List/Map by order in which items are in an XML File

Posted by Brandon Smith on Stack Overflow See other posts from Stack Overflow or by Brandon Smith
Published on 2010-12-23T00:45:13Z Indexed on 2010/12/23 0:54 UTC
Read the original article Hit count: 203

Hello everyone,

What I'm looking to do is to sorta a Java List or Map in the order the items are in a XML File.

For Example

I have a list of function names as so:

  1. functionOne
  2. functionThree
  3. functionTwo

The XML File looks like this:

<xml>
  <function>functionOne</function>
  <function>functionTwo</function>
  <function>functionThree</function>
</xml>

So I would like to sort the list so the function names are as so:

  1. functionOne
  2. functionTwo
  3. functionThree

Now Im trying to do this for Variables as well, so there are around 500+ unique 'items'.

Does anyone have any idea how I can go about doing this? Now for the file that determines that sort order doesn't have to be XML it just what I use the most, it can be anything that can get the job done.

Thanks in advance for your time.

© Stack Overflow or respective owner

Related posts about java

Related posts about Xml