JaxB注释驱动的提取
首先,我对Jaxb还不熟悉,而且最具挑战性的是,我还没有完全了解它 我希望使用注释来减少Xml,而不是生成绑定类 我只想提取xml的一部分,并将其作为Java.lang.String返回。 无需编组或解编。只是想从xml中提取 假设我的XML的结构如下JaxB注释驱动的提取,jaxb,Jaxb,首先,我对Jaxb还不熟悉,而且最具挑战性的是,我还没有完全了解它 我希望使用注释来减少Xml,而不是生成绑定类 我只想提取xml的一部分,并将其作为Java.lang.String返回。 无需编组或解编。只是想从xml中提取 假设我的XML的结构如下 <root> <topMovies> <string>The Godfather (1972)</string> <string>The Shawshank
<root>
<topMovies>
<string>The Godfather (1972)</string>
<string>The Shawshank Redemption (1994)</string>
<string>The Godfather: Part II (1974)</string>
<string>The Lord of the Rings: The Return of the King (2003)</string>
<topMovies>
<root>
最后,我想要一个java字符串,其中提取的xml不需要
考虑到
String topMovies =
"<topMovies>
<string>The Godfather (1972)</string>
<string>The Shawshank Redemption (1994)</string>
<string>The Godfather: Part II (1974)</string>
<string>The Lord of the Rings: The Return of the King (2003)</string>
<topMovies>
";
这可以通过JAXBElement或和XmlAdapter来完成吗?或者创建一个特殊的对象工厂吗?您可以利用带有DOMHandler的@xmlanyement注释来完成这个用例:
以下是我给出的答案的链接,以及包含其他详细信息的类似问题:
更多信息
非常感谢。我认为我需要提高我的谷歌技能:可能重复
String topMovies =
"<topMovies>
<string>The Godfather (1972)</string>
<string>The Shawshank Redemption (1994)</string>
<string>The Godfather: Part II (1974)</string>
<string>The Lord of the Rings: The Return of the King (2003)</string>
<topMovies>
";