JAXB ignoring xml tag attribute

2020-04-13 11:15发布

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 B tags value attribute in my b Instance variable.

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

1条回答
我想做一个坏孩纸
2楼-- · 2020-04-13 12:15

You should just have the following without the @XmlElement annotation:

@XmlRootElement
class A{
  @XmlPath("B/@value")
  String b;
}
查看更多
登录 后发表回答