JAXB ignoring xml tag attribute

三世轮回 提交于 2019-12-31 03:00:29

问题


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:


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

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


来源:https://stackoverflow.com/questions/21188599/jaxb-ignoring-xml-tag-attribute

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!