• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Is there a java API to generate xml with an inline schema definition

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
want to generate the xml file that holds its schema as well as the xml data contain using java,as per my knowledge it is possible in C# .NET.Is it possible in java???

My XML file should be look like as given below.


In my given example my xml file contain data as well as schema I need to generate this type of file from schema using java.
 
Sheriff
Posts: 28401
100
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
moin roy
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.



I try to do that using jaxb and main code part is looking like



but it will generate only




this file did not hold the inline schema part how can I make it possible.

 
Ranch Hand
Posts: 859
IBM DB2 Chrome Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Paul Clapham
Sheriff
Posts: 28401
100
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I get the feeling that Arjun is expecting something else to generate the Schema XML, although so far he hasn't said that.
 
moin roy
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.




But how can I add this jaxb generated xml file under transaction after inline schema.Actually I am new in Java if you give some code snips it will be help full for me and easy to understand
 
William P O'Sullivan
Ranch Hand
Posts: 859
IBM DB2 Chrome Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
moin roy
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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)] .
 
moin roy
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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)] .





I want to generate the total xml file with xml schema(inline Schema) using jaxb API is it possible? using jaxb can we generate xml with schema?As per your procedure you say that generate xml structure using jaxb and inline schema will generate using DOM model and add schema object(created using DOM) and xml data(generated using jaxb) using DOM.but is not possible to do the total thing using jaxb what is done by DOM object?
 
moin roy
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to generate the total xml file with xml schema(inline Schema) using jaxb API is it possible? using jaxb can we generate xml with schema?As per your procedure you say that generate xml structure using jaxb and inline schema will generate using DOM model and add schema object(created using DOM) and xml data(generated using jaxb) using DOM.but is not possible to do the total thing using jaxb what is done by DOM object?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic