I have the fo...">

JAXB ignores xml tag attribute

I read xml files with JAXB. I have the following structure

<A>
  <B value="some string" />
</A>

I have the following model

@XmlRootElement
class A{
  @XmlElement(name = "B", required = true)
  @XmlPath("B/@value")
  String b;
}

I read the tag value attribute B in my instance variable b.

But in some XML files, I have a B tag following the Structure. <#B/> Although JAXB unmarshall files, I become the exception that the format is incorrect. javax.xml.stream.XMLStreamException: ParseError in [row, col]: [19,4]

+2
source share
1 answer

You should only have the following without annotation @XmlElement:

@XmlRootElement
class A{
  @XmlPath("B/@value")
  String b;
}
+1
source

All Articles