简单的 Xml 框架松散映射不起作用 [英] Simple Xml Framework loose mapping not working

查看:21
本文介绍了简单的 Xml 框架松散映射不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用设置了松散映射标志的简单 Xml 框架解析 xml 文档的一部分,但出现异常.

I am trying to parse part of an xml document using Simple Xml Framework with the loose mapping flag set but i get an exception.

XML:

<Body>
    <TopGoalScorersResponse>
        <TopGoalScorersResult>
            <tTopGoalScorer>
                <sName>Alan Dzagoev</sName>
                <iGoals>3</iGoals>
                <sCountry>Y</sCountry>
                <sFlag>http://footballpool.dataaccess.eu/images/flags/ru.gif</sFlag>
                <sFlagLarge>http://footballpool.dataaccess.eu/images/flags/ru.png</sFlagLarge>
            </tTopGoalScorer>
        </TopGoalScorersResult>
    </TopGoalScorersResponse>
</Body>

Java:

TopGoalScorer topGoalScorer = serializer.read(TopGoalScorer.class, xml);

@Root(name="tTopGoalScorer", strict=false)
public class TopGoalScorer {
    @Element(name="sName")
    private String name;

    @Element(name="iGoals")
    private int numGoals;

    @Element(name="sCountry")
    private String country;

    @Element(name="sFlag")
    private String flagImageUrl;
}

异常:

06-22 14:11:46.530: E/Soap(2057): Unable to satisfy @org.simpleframework.xml.Element(data=false, name=sCountry,     required=true, type=void) on field 'country' private java.lang.String uk.co.carr.david.TopGoalScorer.country for class uk.co.carr.david.TopGoalScorer at line 1
06-22 14:11:46.530: E/Soap(2057): org.simpleframework.xml.core.ValueRequiredException: Unable to satisfy @org.simpleframework.xml.Element(data=false, name=sCountry, required=true, type=void) on field 'country' private java.lang.String uk.co.carr.david.TopGoalScorer.country for class uk.co.carr.david.TopGoalScorer at line 1

有什么想法吗?任何帮助将不胜感激.

Any ideas? Any help would be greatly appreciated.

谢谢大卫

推荐答案

这是因为你没有明确元素的路径,尝试使用下一个结构,一切都会好的

It happens because you didn't clarify path to the element, Just try to use next constructions and all will be OK

    @Root(name="tTopGoalScorer", strict=false)
    public class TopGoalScorer {
        @Path("Body/TopGoalScorersResponse/TopGoalScorersResult/tTopGoalScorer/sName")
        @Element
        private String name;
    }

这篇关于简单的 Xml 框架松散映射不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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