Java 如何使用 JAXB/XJC 将 XML 文件转换为对象?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18411021/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I use JAXB/XJC to convert an XML file to an object?
提问by Daniel Esponda
I have been doing research on JAXB and XJC but from the documentation that is out there, including the Oracle pages and some of the Stack Overflow questions here, I don't think there is a clear definition of what is the difference between JAXB and XJC and how to use it to convert an XML file to an object.
我一直在做研究JAXB和XJC但从那就是文档在那里,包括Oracle网页和一些在这里,我不觉得有什么是什么JAXB和XJC的区别一个明确的定义堆栈溢出的问题以及如何使用它将 XML 文件转换为对象。
So from my understanding JAXB is method for XML -> Java parsing and vice versa and xjc is one implementation for it that is included in the java tools?
因此,根据我的理解,JAXB 是 XML -> Java 解析的方法,反之亦然,而 xjc 是 Java 工具中包含的一种实现?
采纳答案by bdoughan
JAXB (JSR-222)implementations convert instances of Java classes (that may contain annotations) to/from XML. XJC (XML to Java Compiler) is a utility for generating those objects from an XML schema. It is included as part of the JDK since Java SE 6.
JAXB (JSR-222)实现将 Java 类(可能包含注释)的实例转换为 XML 或从 XML 转换。XJC(XML to Java Compiler)是一个用于从 XML 模式生成这些对象的实用程序。自 Java SE 6 起,它就作为 JDK 的一部分包含在内。
Exanple
例子
Here is a link to my blog that demonstrates how to generate a Java model from an XML Schema:
这是我的博客的链接,它演示了如何从 XML 模式生成 Java 模型:
回答by xQbert
Not sure this is what you're after but it seems close...
不确定这是你想要的,但它似乎很接近......
Use Java Architecture for XML Binding (JAXB) xjc tooling to compile an XML schema file into fully annotated Java classes.
使用 Java Architecture for XML Binding (JAXB) xjc 工具将 XML 模式文件编译为完全注释的 Java 类。