Reputation: 135
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
Upvotes: 3
Views: 3955
Reputation: 149047
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.
Upvotes: 4
Reputation: 3297
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.
Upvotes: 0
Reputation: 355
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.
Upvotes: 0