Paul Clapham wrote:The example you posted is XML. So any code, Java or otherwise, which can produce XML can produce that XML. The only requirement is that the code must be namespace-compliant, which all of the XML processing classes in the standard Java API are.
William P O'Sullivan wrote:dom4j is your friend:
produces:
Write a helper that produces the inline schema, then add the Marshaled XML data after </xs:schema>
BTW: I have only scratched the power of dom4j here, I believe there are many helper methods to create Entities, ComplexTypes etc.. I was lazy and it's Friday!
Pat.
William P O'Sullivan wrote:Your marshalling an object named "transaction", so Jaxb assumes that is the xml document root element.
You could extend a base (superClass) object that contains all the inline schema as an attribute and have printed out as well.
Since it is Friday, and it's almost time to hit the bar, I tweaked my program a bit.
Some of the coding conventions here are not to be taken literally! I am really sick of getters and setters these days! ;)
After:
Add:
And After:
Add:
This produces:
which is very very close to what you want to accomplish (I believe).
The key here is the line is "transactionElement.add". Since the XML is being built, you can add anything (within reason here), even other XML!
Your problem is that jaxb is adding <transaction> as the root.
Pat.
arjun ray wrote:
William P O'Sullivan wrote:Your marshalling an object named "transaction", so Jaxb assumes that is the xml document root element.
You could extend a base (superClass) object that contains all the inline schema as an attribute and have printed out as well.
Since it is Friday, and it's almost time to hit the bar, I tweaked my program a bit.
Some of the coding conventions here are not to be taken literally! I am really sick of getters and setters these days! ;)
After:
Add:
And After:
Add:
This produces:
which is very very close to what you want to accomplish (I believe).
The key here is the line is "transactionElement.add". Since the XML is being built, you can add anything (within reason here), even other XML!
Your problem is that jaxb is adding <transaction> as the root.
Pat.
Thanks for your help many many thanks to you.Can you tell me that with out dom4j can I do it because I want do it using sun(oracle) provided API.Is there any API by which I can do it like stax or DOM. I heard about that stax is better than dom to xml write,so I want to use stax is it possible to set namespace and other thing.
I have another question is true that jaxb is only use to convert xml to xml schema(un marshaling) and xml schema to xml(marshaling) and if I need to write xml file then we need to use jaxb[DOM,STAX(stream based reading writing),SAX(stream only reading)] .
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |