I get a valuerequired exception error that I can't get my head around. If I set the xmlns to required = false everything works but the xmlns value is null altough all the other values are set as expected.
xml I am reading:
<test xmlns="somestring"
id="123456"
timestamp="2013-05">
<value1>12</value1>
<value2>3 </value2>
</test>
This is the error message:
02-15 18:05:55.988: W/System.err(31450): org.simpleframework.xml.core.ValueRequiredException: Unable to satisfy @org.simpleframework.xml.Attribute(empty=, name=xmlns, required=true) on field 'xmlns' private java.lang.String parsing.Test.xmlns for class parsing.Test at line 1
Code:
@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 method:
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;
}
The attribute xmlns is reserved for namespaces, this is why you get the error.