问题
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