質問

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...

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top