XML 解析在 lwuit 应用程序的 android 版本上不起作用

发布于 2025-01-03 09:48:31 字数 162 浏览 2 评论 0原文

我使用 Kxml2 解析器来解析从远程页面获得的 xml 响应。用于用户认证,返回的xml给出了用户的一些详细信息。该应用程序使用 LWUIT 1.5 构建,适用于 MIDP 和 Blackberry 版本。 在 Android 版本上它不起作用。为了让 Android 正常工作,我需要添加任何额外的规范吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

潦草背影 2025-01-10 09:48:31

LWUIT中有一个XMLParser,非常好用。您可以尝试使用它。它在我的 MIDP 和 BB 应用程序中运行良好。我无法在 Android 中测试它,但我认为这可能是解决方案。如何将 LWUIT 应用程序移植到 Android?

ADD

好吧,我会尽力解释这个解析器的使用

。您需要导入这个包:

import com.sun.lwuit.xml.Element;
import com.sun.lwuit.xml.XMLParser;

在我的项目中,我从 HTTPConnection 中提取 XML。

假设 XML 如下:

  <?xml version="1.0" encoding="UTF-8"?>
    <xml>
     <TagFromXML>
       <child>
         <data>HI</data>
       </child>
     </TagFromXML>
    <TagFromXML>
      <child>
         <data>HI2</data>
       </child>
     </TagFromXML>
    </xml>

然后执行以下操作:

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());
}

您将得到

HI

HI2

我希望这对您有用。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文