4

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>
IMSoP
  • 89,526
  • 13
  • 117
  • 169
GeniDeveloper
  • 361
  • 3
  • 18

2 Answers2

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

bdoughan
  • 147,609
  • 23
  • 300
  • 400
0

Just read

Or

Both have more than enough information. And so do a lot of other SO questions...

Community
  • 1
  • 1
Mattsjo
  • 627
  • 5
  • 11
  • It works fine without this the im: in im:id="one" but when I add it, it generate an exception. Please help, I try many solutions before asking. – GeniDeveloper Aug 15 '13 at 13:29
  • Cool, glad to hear that! Accept the answer if it helped (I believe you'll get a bronze badge if you do ;) ) – Mattsjo Aug 15 '13 at 13:31
  • My problem is with this : im:id="one", I can't found how to parse it, please give me a working sample code. Here is the documentation : http://simple.sourceforge.net/download/stream/doc/tutorial/tutorial.php#namesoace – GeniDeveloper Aug 15 '13 at 13:35