0
我得到一个值得我需要的异常错误,我无法得到我的头。如果我将xmlns设置为required = false,但所有其他值都按预期设置,但xmlns值为空。Simplexml valuerequired exception
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:无法满足字段'xmlns'的@ org.simpleframework.xml.Attribute(empty =,name = xmlns,required = true)private java.lang.String parsing.Test.xmlns用于解析类。 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;
}}
Serialize方法:
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;
}