• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Need help with displaying local xml file in android

coder01

Lurker
Jun 6, 2011
1
0
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,
Code:
<?xml version="1.0" encoding="utf-8" ?>
<Books>
    <Book id = "1">
    <Description>This book is about cooking</Descriptiion>
   </Book>
</Books>
Here is the code I am working with,

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());
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones