Parse nested XML nodes in Android



I have XML file like this:



<catalog>
<category>
<books>
<book>
<id>book1</id>
<description>short description</description>
<pages>number of pages</pages>
<author>Anonymous</author>
<name>Book title</name>
</book>
<book>
<id>book2</id>
<description>short description</description>
<pages>number of pages</pages>
<author>Anonymous</author>
<name>Book title</name>
</book>
</books>
</category>
<category>
<books>
<book>
<id>book3</id>
<description>short description</description>
<pages>number of pages</pages>
<author>Anonymous</author>
<name>Book title</name>
</book>
</books>
</category>
</catalog>


And I need an ArrayList with Categories and ArrayList with Books. Here are my Book and Category classes:



public class Book
{
private String id;
private String description;
private String pages;
private String author;
private String name;
}
public class Category {
private ArrayList<Book> books;
private String name;
}


What is the easiest way to do this? Using only android libraries and stuff would be better than using some libraries not for commercial use for my task. I tried some DOM parsers, but it didn't work good.


No comments:

Post a Comment