Create a Stax Writer API for the given XML schema
I have an XML schema. I wrote a thin layer on top of Stax to allow for consistent documents on the fly (I don't want a dom-like API, I want a low / no trace). The API only has methods like:
writeCar(String manufacturer)
writeWheels(String manufacturer, boolean winter)
...
They perform a status check and then call the appropriate stax methods.
The specialty is that there are no writeEndXXX methods (my schema is unambiguous, so you can't have a car inside a wheel element. This means I always know when to close open elements). The only exception is the presence of a flash () which will write all pending end tags.
writeCar(..) // <car>
writeWheels(..) // inside the car <wheels>
writeCar(..) // close the pending tags </wheels></car> and new car <car>
flush() // this writes all pending close tags
It works well. Now the circuit is developing :)
Now I am updating the API manually. Because I'm virtuous, I don't want to do that :). Is there a tool available that would generate such an API (or similar) given the XML schema definition?
source to share
JAXB based
- Generate XSD from your XML. You can also use this link or another tool works great.
- Generating classes from XSD using XJC, Maven plugin see here
- Using any JAXB tutorial to marshal and read and write xml immediately. see here
I suggest you also this link
Hope this helps you.
source to share