1

What way JAXB give to convert this type of XML conversion

<options>
  <option name="name">https://abc.com/</option>
  <option name="name2">https://abc.com/</option>
</options>

I created two object classes for it. It does not fill object with data and set null values for tag where it should set URL like https://abc.com/.

Options.java and Option.java

Options class contain this setter

  @XmlElement(name = "option")
  public void setOption(List<Option> option) {
    this.option = option;
  }

Option.java class is:

@XmlRootElement(name = "option")
public class Option {

  String name;

  String option;

  public Option() {
    super();
  }

  public Option(String name, String option) {
    super();
    this.name = name;
    this.option = option;
  }

  public String getName() {
    return name;
  }

  @XmlAttribute
  public void setName(String name) {
    this.name = name;
  }

  public String getOption() {
    return option;
  }

  public void setOption(String option) {
    this.option = option;
  }
Muhammad Imran Tariq
  • 22,654
  • 47
  • 125
  • 190
  • Follow this: http://stackoverflow.com/questions/3284786/java-jaxb-unmarshall-xml-attributes-to-specific-java-object-attributes – Juned Ahsan May 21 '13 at 07:53

1 Answers1

3

You can use the @XmlValue annotation on the option property of the Option class.

bdoughan
  • 147,609
  • 23
  • 300
  • 400