Does JAXB always require XSD

匿名 (未验证) 提交于 2019-12-03 08:57:35

问题:

http://www.oracle.com/technetwork/articles/javase/index-140168.html#binsch - This article says "JAXB requires that the XML document you want to access has a schema"

Here is a Hello World example , uses hello.xsd

http://jaxb.java.net/tutorial/section_1_3-Hello-World.html#Hello%20World -

And here is a Hello World example without using any xsd .

http://www.mkyong.com/java/jaxb-hello-world-example/

Does specification says that JAXB also works without xsd ,if that is true then how far the term "Binding" justifies. I believe binding happens through binding the schema.

Carification will be helpful . Thanks

回答1:

JAXB 2 (JSR-222) implementations do not require an XML schema. You can start from an object model. You only need to add annotations where you want to override the default mapping behaviour.

Note: The link that you cited (http://www.oracle.com/technetwork/articles/javase/index-140168.html#binsch) was for JAXB 1 (JSR-31) which did require an XML schema. JAXB 2 which is what most people are referring to when they say JAXB does not require an XML schema.



回答2:

the Customer class in the tutorial is nothing but a binding object that will be generated from XSD using JAXB. The guy escaped that in his tutorial.



回答3:

xsd is just a formal representation of xml, analogous to 'Class' for an 'Object' . You can have a compliant xml without an xsd (in which case the xsd is hidden). While it is true that we start with xsd and generate java objects for the most part, you can do things the other way around as well. 'schemagen' actually lets you come up with a xsd for a given java class. This is just to say that there are multiple starting points.



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