kamal
kamal

Reputation: 1193

How to get xml attribute using JAXB

this is my xml:

<?xml version="1.0" encoding="UTF-8" ?>
    <organization>
      <bank>
        <description>aaa</description>
        <externalkey>123</externalkey>
        <property name="pName" value="1234567890" />
      </bank>
   </organization>

I used JAXB and unmarshall for this xml and I can get description and externalkey. But I cannot get property name with value.

Upvotes: 6

Views: 9609

Answers (1)

bdoughan
bdoughan

Reputation: 148977

Bank

You need to change the property property from a String to a domain object.

@XmlAccessorType(XmlAccessType.FIELD)
public class Bank {
    private String description;
    private String externalkey;
    private Property property;
}

Property

Then your Property object would look something like:

@XmlAccessorType(XmlAccessType.FIELD)
public class Property {

    @XmlAttribute
    private String name;

    @XmlAtrribute
    private String value;

}

Upvotes: 10

Related Questions