Hi,
I have a local xml file in my android app. I am trying to read it. How can I read the id and the description for the book.Here is the xml for it,
Here is the code I am working with,
I have a local xml file in my android app. I am trying to read it. How can I read the id and the description for the book.Here is the xml for it,
Code:
<?xml version="1.0" encoding="utf-8" ?>
<Books>
<Book id = "1">
<Description>This book is about cooking</Descriptiion>
</Book>
</Books>
Code:
InputStream is =null;
is = getResources().openRawResource(R.raw.myXml);
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
try {
DocumentBuilder builder = factory.newDocumentBuilder();
Document dom = builder.parse(is);
dom.getDocumentElement().normalize();
stringBuffer.append("Root element " + dom.getDocumentElement().getNodeName());
// gets the value "Books"
show1.setText(stringBuffer.toString());