How to parse this with simpleXml or JAXB (I want to convert it to a java object) :
<properties xmlns:im="http://itunes.apple.com/rss">
<id im:id="one">id1</id>
<name>name1</name>
</properties>
How to parse this with simpleXml or JAXB (I want to convert it to a java object) :
<properties xmlns:im="http://itunes.apple.com/rss">
<id im:id="one">id1</id>
<name>name1</name>
</properties>
You could map it with the following classes using a JAXB (JSR-222) implementation.
Properties
import javax.xml.bind.annotation.*;
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class Properties {
private Id id;
private String name;
}
Id
Since the attribute is namespace qualified you need to include this in the @XmlAttribute
annotation.
import javax.xml.bind.annotation.*;
@XmlAccessorType(XmlAccessType.FIELD)
public class Id {
@XmlAttribute(namespace="http://itunes.apple.com/rss")
private String id;
@XmlValue
private String value;
}
For More Information
Just read
Or
Both have more than enough information. And so do a lot of other SO questions...