XML : Simple-xml parser - How would I parse a complicated XML file like this?

I have been looking at the simple-xml jar file and trying to use it for an assignment. I have a very complicated file I have to parse and am unsure which way to go about it. I have looked at some examples already(http://simple.sourceforge.net/download/stream/doc/examples/examples.php).

  <plist version="1.0">  <dict>  <key>Major Version</key><integer>1</integer>  <key>Minor Version</key><integer>1</integer>  <key>Application Version</key><string>8.0</string>  <key>Features</key><integer>5</integer>  <key>Music Folder</key><string>file://localhost/G:/MP3/</string>  <key>Library Persistent ID</key><string>3B880FD26820EC45</string>  <key>Tracks</key>  <dict>      <key>1071</key>      <dict>          <key>Track ID</key><integer>1071</integer>          <key>Name</key><string>All I Really Want</string>          <key>Artist</key><string>Alanis Morissette</string>          <key>Album</key><string>Jagged Little Pill</string>          <key>Genre</key><string>Alt.Rock</string>          <key>Kind</key><string>MPEG audio file</string>          <key>Size</key><integer>6914748</integer>          <key>Total Time</key><integer>284708</integer>          <key>Track Number</key><integer>1</integer>          <key>Year</key><integer>1995</integer>          <key>Date Modified</key><date>2008-07-21T22:31:33Z</date>          <key>Date Added</key><date>2008-07-17T19:20:02Z</date>          <key>Bit Rate</key><integer>192</integer>          <key>Sample Rate</key><integer>44100</integer>          <key>Artwork Count</key><integer>1</integer>          <key>Persistent ID</key><string>3B880FD268212AED</string>          <key>Track Type</key><string>File</string>          <key>Location</key><string>file://localhost/G:/MP3/Alanis%20Morissette/Jagged%20Little%20Pill/01%20All%20I%20Really%20Want.mp3</string>          <key>File Folder Count</key><integer>-1</integer>          <key>Library Folder Count</key><integer>-1</integer>      </dict>      <key>1074</key>      <dict>          <key>Track ID</key><integer>1074</integer>          <key>Name</key><string>You Oughta Know</string>          <key>Artist</key><string>Alanis Morissette</string>          <key>Album</key><string>Jagged Little Pill</string>          <key>Genre</key><string>Alt.Rock</string>          <key>Kind</key><string>MPEG audio file</string>          <key>Size</key><integer>6064617</integer>          <key>Total Time</key><integer>249286</integer>          <key>Track Number</key><integer>2</integer>          <key>Year</key><integer>1995</integer>          <key>Date Modified</key><date>2008-07-21T22:31:34Z</date>          <key>Date Added</key><date>2008-07-17T19:20:02Z</date>          <key>Bit Rate</key><integer>192</integer>          <key>Sample Rate</key><integer>44100</integer>          <key>Play Count</key><integer>2</integer>          <key>Play Date</key><integer>3300167574</integer>          <key>Play Date UTC</key><date>2008-07-29T16:12:54Z</date>          <key>Skip Count</key><integer>2</integer>          <key>Skip Date</key><date>2008-07-28T02:21:52Z</date>          <key>Artwork Count</key><integer>1</integer>          <key>Persistent ID</key><string>3B880FD268212AEF</string>          <key>Track Type</key><string>File</string>          <key>Location</key><string>file://localhost/G:/MP3/Alanis%20Morissette/Jagged%20Little%20Pill/02%20You%20Oughta%20Know.mp3</string>          <key>File Folder Count</key><integer>-1</integer>          <key>Library Folder Count</key><integer>-1</integer>      </dict>    </dict>  </dict>    

So far I am only trying to start it but would it be something like this:

     @Root     public static class Point {      @Path("dict/dict/dict/key/string/[1]")@Element    private final String kind;      public Point(@Element(name="kind") String kind ) {       this.kind = kind;    }  }    public static void main(String[] list) throws Exception {    Persister persister = new Persister();    File file = new File("example3.xml");    Point example = persister.read(Point.class, file);      System.out.println(example.kind);  }    

If this does not work, does anyone have any experience with other xml parsers that would make this type of xml file easy?

No comments:

Post a Comment