1. Download our Official Android App: Forums for Android!

Apps Need help with displaying local xml file in android

Discussion in 'Android Development' started by coder01, Jun 6, 2011.

  1. coder01

    coder01 Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    1
    Joined:
    Jun 6, 2011

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

    Code (Text):
    1.  
    2. InputStream is =null;
    3.         is = getResources().openRawResource(R.raw.myXml);
    4.         DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    5.         try {
    6.             DocumentBuilder builder = factory.newDocumentBuilder();
    7.             Document dom = builder.parse(is);
    8.             dom.getDocumentElement().normalize();
    9.                                            
    10.             stringBuffer.append("Root element " + dom.getDocumentElement().getNodeName());
    11.  // gets the value "Books"
    12.  
    13. show1.setText(stringBuffer.toString());
    14.  
     

    Advertisement

  2. satellitemundo

    Rank:
    None
    Points:
    15
    Posts:
    29
    Joined:
    Aug 18, 2010

    Aug 18, 2010
    29
    0
    15

Share This Page

Loading...