I use Kxml2 parser to parse the xml response I get as a response from a remote page. It is for user authentication, and the returned xml gives several details about the user. The app is built with LWUIT 1.5 and it works on MIDP and Blackberry versions. On the Android version it doesn't work. Is there any extra specification I am supposed to add, for Android to work properly?
XML parsing not working on android build of lwuit app
"extra specification" for LWUIT is outlined in answers to this question: #7402067 –
Slowwitted
Thanks @Slowwitted but I already added the extra specs [permissions]. I ended up restarting my system and it worked. But I am yet to test on a real device. –
Disreputable
There is a XMLParser in LWUIT, is very easy to use. You can try to use it. It works fine in my MIDP and BB apps. I can't test it in Android but I think It could be the solution. How do you port your LWUIT apps to Android?
ADD
Well I will try to explain the use of this Parser the best that I can
You need to import this packages:
import com.sun.lwuit.xml.Element;
import com.sun.lwuit.xml.XMLParser;
In my project I extract a XML from an HTTPConnection
.
Suppose out XML is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<xml>
<TagFromXML>
<child>
<data>HI</data>
</child>
</TagFromXML>
<TagFromXML>
<child>
<data>HI2</data>
</child>
</TagFromXML>
</xml>
Then do the following:
InputStream is = hc.openInputStream();
InputStreamReader isr = new InputStreamReader(is, "utf-8");
XMLParser myParser = new XMLParser();
Element e = myParser.parse(isr);
Vector tagVector = e.getChildrenByTagName("TagFromXML");
for(int i = 0; i<tagVector.size();i++){
Element singleTag = (Element) tagVector.elementAt(i);
Element child = (Element) (singleTag.getChildrenByTagName("child")).elementAt(0);
Element data = (Element) (child.getChildrenByTagName("data")).elementAt(0);
System.out.println("DATA: " + data.getChildAt(0).getText());
}
You will get
HI
HI2
I hope this wroks for you.
You used it successfully? Wow! Could u please illustrate with an example? If it works in LWUIT itself it means its abstracted, so it should work in Android. –
Disreputable
Thanks for the example @jmunoz, will digest in a bit. For porting LWUIT to Android, you will need Eclipse IDE. I followed the instructions here and here. I had to read and reread to really understand what Thorsten said in his link (second link) ]. But it paid out in the end. It also helps to download their examples and study the code. I am here if you need more help :) –
Disreputable
© 2022 - 2024 — McMap. All rights reserved.