Having problem while parsing XML document in blackberry -
i trying to parse data 1 url, it's not displaying parse data on screen:
public class xml_parsing_sample extends uiapplication { //creating member variable mainscreen mainscreen _screen= new mainscreen(); //string variables store values of xml document string _node,_element; connection _connectionthread; public xml_parsing_sample() { // todo auto-generated constructor stub _screen.settitle("xml parsing");//setting title _screen.add(new richtextfield("requesting.....")); _screen.add(new separatorfield()); //_screen.add(new richtextfield("xml data")); pushscreen(_screen); // creating screen "system.out.println("1111111111111");" //creating connection thread run in background _connectionthread = new connection(); "system.out.println("222222222222222");" _connectionthread.start();//starting thread operation "system.out.println("after connection run");" } public void updatefield(string node, string element){ //receiving parsed node , value thread //and updating here //so can displayed on screen string title="title"; _screen.add(new richtextfield(node+" : "+element)); if(node.equals(title)){ _screen.add(new separatorfield()); } } public static void main(string[] args) { // todo auto-generated method stub xml_parsing_sample application = new xml_parsing_sample(); //create new instance of application //and start application on event thread application.entereventdispatcher(); }}
and displaying parse data on emulator using following code not works.
public class connection extends thread { public connection() { // todo auto-generated constructor stub super(); " system.out.println("outside run method");" } public void run(string _node, string _element){ "system.out.println("inside run method");" // define variables later used parsing document doc; streamconnection conn; try{ //providing location of xml file, //your address might different conn=(streamconnection)connector.open ("http://magazine.ateemo.com/magazines/by_publisher/2"); //next few lines creates variables open //stream, parse it, collect xml data , //extract data required. //in case elements, //node , values of element documentbuilderfactory docbuilderfactory = documentbuilderfactory. newinstance(); documentbuilder docbuilder = docbuilderfactory.newdocumentbuilder(); docbuilder.isvalidating(); doc = docbuilder.parse(conn.openinputstream()); doc.getdocumentelement ().normalize (); nodelist list=doc.getelementsbytagname("*"); _node=new string(); _element = new string(); //this "for" loop used parse through //xml document , extract elements , //value, can displayed on device (int i=0;i<list.getlength();i++){ node value=list.item(i). getchildnodes().item(0); _node=list.item(i).getnodename(); _element=value.getnodevalue(); updatefield(_node,_element); }//end }//end try //will catch exception thrown xml parser catch (exception e){ system.out.println(e.tostring()); } }//end connection function private void updatefield(string _node, string _element) { // todo auto-generated method stub } }
the first step figure out if problem parsing itself, or display of parsed result. start adding debug printouts see if parser working correctly. way can isolate problem down smaller part of code.
Comments
Post a Comment