Simple XML framework on android, class attribute

让人想犯罪 __ 提交于 2020-01-23 10:46:12

问题


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 File (no control on this one):

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

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

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.

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


回答1:


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


来源:https://stackoverflow.com/questions/8862548/simple-xml-framework-on-android-class-attribute

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