0

理解できない valuerequired 例外エラーが発生します。xmlns を required = false に設定すると、すべてが機能しますが、xmlns 値は null ですが、他のすべての値は期待どおりに設定されます。

私が読んでいるxml:

<test xmlns="somestring"           
id="123456"   
timestamp="2013-05">         
<value1>12</value1>     
<value2>3 </value2>    
</test>

これはエラーメッセージです:

02-15 18:05:55.988: W/System.err(31450): org.simpleframework.xml.core.ValueRequiredException: @org.simpleframework.xml.Attribute(empty=, name=xmlns, required=true を満たすことができません) フィールド 'xmlns' のプライベート java.lang.String parsing.Test.xmlns for class parsing.Test at line 1

コード:

 @Root(name = "test") 
public class Test {


    @Element(name = "value1")
    private String value1;
    @Element(name ="value2")
    private String value2;

    @Attribute(name = "xmlns")
    private String xmlns;
    @Attribute(name = "id")
    private String id;
    @Attribute(name = "timestamp")
    private String timestamp;



    public Test () {
    }

    public Test (String value1, String value2, String xmlns, String id, String timestamp) {
        this.value1 = value1;
        this.value2 = value2;
        this.xmlns = xmlns;
        this.id = id;
        this.timestamp = timestamp;
    }

    public String getValue1() {
        return value1;
    }

    public String getValue2 () {
        return value2;
    }
    public String getXMLns () {
        return xmlns;
    }
    public String getId () {
        return id;
    }
    public String getTimeStamp () {
        return timestamp;
    }}

シリアル化方法:

public Test DeSerialize (String xml) {
    //System.out.println("xml:  \n " + xml);
    try {
        test = serializer.read(Test.class, xml);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return test;
}
4

1 に答える 1

1

属性 xmlns は名前空間用に予約されているため、エラーが発生します。

于 2013-02-18T10:16:49.093 に答える