如何使用 simpleXml 或 JAXB 解析它(我想将其转换为 java 对象):
<properties xmlns:im="http://itunes.apple.com/rss">
<id im:id="one">id1</id>
<name>name1</name>
</properties>
如何使用 simpleXml 或 JAXB 解析它(我想将其转换为 java 对象):
<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