Can anyone help me with an android XML parser?

scarletwolf031

New Member
I don't usualy ask for help, I always do my research and try to find the solutions by myself, but this time I'm really stuck...I've a lot of experience with some languages, but not with java...So, what I'm trying to do is an application, that have dynamic layout, and loads it from an XML file on a specific host.My first problem is that apparently, it's not possible to read the XML from the main thread, so I had to learn about threads and Asynctaks, and I've decided to use a simple thread and store the values in some global variables that I created, but it's not working...I've also tryed to use SAX for the XML parser, but I prefer DOM.I'm just trying to do this for more than 3 days, I'm becoming a little mad with this, I hope that someone can help me, here's my code:This is the class where I'm defining my vars. They are all supposed to handle more than one value, except for the XML one, that will store the URL of the XML to use it in the thread.\[code\]public class Info { public static String Param1[]; public static String Param2[]; public static String Param3[]; public static String Param4[]; public static String Param5[]; public static String Param6[]; public static String XML;}\[/code\]And here is my main thread:\[code\]//Create the basic layoutScrollView sv = new ScrollView(this); LinearLayout ll = new LinearLayout(this); ll.setOrientation(LinearLayout.VERTICAL); sv.addView(ll);Info.XML="mylink";Thread thread = new Thread(){ @Override public void run() { try { URL url = new URL(Info.XML); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse(new InputSource(url.openStream())); doc.getDocumentElement().normalize(); NodeList ActionContainers = doc.getElementsByTagName("ActionContainer"); Node mainContainer = ActionContainers.item(0); Element Container = (Element) mainContainer; NodeList Actions = Container.getElementsByTagName("Action"); for (int i = 0; i < Actions.getLength(); i++) { Node mainAction = Actions.item(i); Element Action = (Element) mainAction; Info.Param1=Action.getAttribute("Param1"); Info.Param2=Action.getAttribute("Param2"); Info.Param3=Action.getAttribute("Param3"); Info.Param4=Action.getAttribute("Param4"); Info.Param5=Action.getAttribute("Param5"); Info.Param6=Action.getAttribute("Param6"); } } catch (Exception e) { Info.XML="Erro"; } }};try{ thread.start();} catch(Exception e){ Info.XML="Erro";} EditText et = new EditText(this); et.setText(Info.XML); ll.addView(et); setContentView(sv);\[/code\]No exception is being detected, It simply doesn't return the xml information...I hope someone can give me a little help here.ThanksEDIT:Here is the XML:\[code\]<appname Version="yyy" WrittenOn="yyy"><Config> <Page Id="yyy"> <ActionContainer Id="yyy"> <Action Param1="xxx" Param2="xxx" Param3="xxx" Param4="xxx" Param5="xxx" Param6="xxx"></Action> <Action Param1="xxx" Param2="xxx" Param3="xxx" Param4="xxx" Param5="xxx" Param6="xxx"></Action> <Action Param1="xxx" Param2="xxx" Param3="xxx" Param4="xxx" Param5="xxx" Param6="xxx"></Action> <Action Param1="xxx" Param2="xxx" Param3="xxx" Param4="xxx" Param5="xxx" Param6="xxx"></Action> ... </ActionContainer> </Page></Config>\[/code\]I need all the xxx, and I would like to have them on a multimensional array if possible.
 
Back
Top