4

如何使用 simpleXml 或 JAXB 解析它(我想将其转换为 java 对象):

<properties xmlns:im="http://itunes.apple.com/rss">
   <id im:id="one">id1</id>
   <name>name1</name>
</properties>
4

2 回答 2

1

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

于 2013-08-15T14:21:03.803 回答
0

刚读

或者

两者都有足够的信息。还有很多其他的SO问题......

于 2013-08-15T13:24:19.333 回答