XML parsing not working on android build of lwuit app

依然范特西╮ 提交于 2019-11-29 15:36:12

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!