Android- XML database from the ASSETS -


i want pull out data xml database placed in assets folder. // sample of database

<?xml version="1.0" encoding="utf-8" ?>    <levels>     <level id ="0">      <start>3,2</start>    <one>1,1</one>     </level>     <level id ="1"> <start>3,2</start>   <one>4,1</one>      </level>   </levels> 

i want data pull id example id=0 returns < start>3,2< /start> < one>1,1< /one>. there 1 problem - dont know how please me //--------------------------------------------------------------------------------------- edit : im getting error please check xmlparser class:

 package com.example.com.worfield.barak;    import java.io.ioexception;  import java.io.stringreader;       import javax.xml.parsers.documentbuilder;  import javax.xml.parsers.documentbuilderfactory; import javax.xml.parsers.parserconfigurationexception;   import org.apache.http.impl.client.defaulthttpclient;  import org.w3c.dom.document;  import org.w3c.dom.node;  import org.w3c.dom.nodelist;  import org.xml.sax.inputsource;  import org.xml.sax.saxexception;   import android.content.context;  import android.sax.element;   import android.util.log;   public class xmlparser   { context context;     public xmlparser(context c)      {     context = c;  }  public document getdomelement() {     document doc = null;     try     {     documentbuilderfactory dbf = documentbuilderfactory.newinstance();     documentbuilder db = dbf.newdocumentbuilder();     doc = db.parse( context.getassets().open("level5x5three.xml"));      }     catch(exception ex)     {          log.e("xml parse error", "eror in getdomelement()");     }         return doc; } public string getvalue(element e, string str)  {           nodelist n = ((document) e).getelementsbytagname(str);        //problem     return this.getelementvalue(n.item(0)); }  public final string getelementvalue( node elem )  {          node child;          if( elem != null){              if (elem.haschildnodes()){                  for( child = elem.getfirstchild(); child != null; child = child.getnextsibling() ){                      if( child.getnodetype() == node.text_node  ){                          return child.getnodevalue();                      }                  }              }          }          return "";   }      } 

just follow below tutorial explains need

http://www.androidhive.info/2011/11/android-xml-parsing-tutorial/


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

qt - Errors in generated MOC files for QT5 from cmake -