本文介紹了JAXB 忽略 xml 標記屬性的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我使用 JAXB 讀取 xml 文件.我有以下結構
I read xml files with JAXB. I have the following structure
<A>
<B value="some string" />
</A>
我有以下型號
@XmlRootElement
class A{
@XmlElement(name = "B", required = true)
@XmlPath("B/@value")
String b;
}
我在我的 b 實例變量中讀取了 B 標簽值屬性.
I read the B tags value attribute in my b Instance variable.
但在一些 XML 文件中,我在結構 <#B/>
之后的 B 標記中有當 JAXB 解組文件時,我成為格式不正確的例外.javax.xml.stream.XMLStreamException: ParseError at [row,col]:[19,4]
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]
推薦答案
你應該只有以下沒有 @XmlElement
注釋:
You should just have the following without the @XmlElement
annotation:
@XmlRootElement
class A{
@XmlPath("B/@value")
String b;
}
這篇關于JAXB 忽略 xml 標記屬性的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!