value3 using JAXB? The substring of my XML is as follows: value3

How to parse <foo value1 = "a" value2 = "b"> value3 </foo> using JAXB?

The substring of my XML is as follows:

<foo value1="a" value2="b">value3</foo> 

I am trying to parse this with JAXB. I managed to parse the values โ€‹โ€‹of value1 and value2, but I had problems with the "root" value, since it does not have any tag associated with it.

My class:

 @XmlType(propOrder = {"value3"}, name = "foo") @XmlAccessorType(XmlAccessType.FIELD) public class Foo { @XmlAttribute private String value1; @XmlAttribute private String value2; @XmlElement(name = "") private String value3; } 

Any ideas?

+6
source share
1 answer

You can use the @XmlValue annotation:

 @XmlAccessorType(XmlAccessType.FIELD) public class Foo { @XmlAttribute private String value1; @XmlAttribute private String value2; @XmlValue private String value3; } 
+6
source

Source: https://habr.com/ru/post/890589/


All Articles