在Android上,类属性简单的XML框架 [英] Simple XML framework on android, class attribute

查看:326
本文介绍了在Android上,类属性简单的XML框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

香港专业教育学院有一个奇怪的问题,在Android simplexml的框架。我试着去阅读和从XML源填充对象称为weatherdata。

Ive got a weird problem with simplexml framework on android. Im trying to read and fill an object called weatherdata from a xml source.

XML文件(在这一个没有控制):

XML File (no control on this one):

<weatherdata>
    <product class="pointData">
        ....
    </product>
</weatherdata>

所以,我的java文件看起来像:

So my java file looks like :

@Root(name = "weatherdata", strict=false)
public class Weatherdata {

    @Element(name="product", required = true)
    protected ProductType product;

不过,我得到一个非常奇怪的错误:

But I get a very weird error :

01-14 14:22:28.919: W/System.err(18011): java.lang.ClassNotFoundException: pointData in loader dalvik.system.PathClassLoader

如果我试图类= ProductType.class在@Element领域,它并不关心。甚至当我创建我谟与构造pointData类,错误并没有改变。它看起来像阶级作为保留关键字乱用简单的XML框架2.6.2。

If i try to class=ProductType.class in the @Element field, it doesn't care. Even when I create the pointData class in my projet with a constructor, the error doesnt change. It looks like "class" as a reserved keyword mess with simple xml framework 2.6.2.

我不能改变的XML。任何想法,我怎么能解决呢?得益于领先。

I can't change the xml. Any idea how I could solve that ? thanks ahead.

推荐答案

尝试使用TreeStrategy来替代类别的东西。

Try using TreeStrategy to substitute the "class" for something else.

Strategy strategy = new TreeStrategy("clazz", "len"); // clazz substitute for class,
                                                      // and len for array lengths
Serializer serializer = new Persister(strategy);

这篇关于在Android上,类属性简单的XML框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆