aspose file tools*
The moose likes XML and Related Technologies and the fly likes How to add xml schema within xml using jaxb Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "How to add xml schema within xml using jaxb" Watch "How to add xml schema within xml using jaxb" New topic
Author

How to add xml schema within xml using jaxb

moin roy
Greenhorn

Joined: Mar 28, 2012
Posts: 15
I want to add schema in xml file using jaxb.I can generate java sources from schema and generate xml file from this sources but now I want to add this schema with in this xml.
My schema is look like, It is only a demo schema originally it is also big.



Please give some code snips to configure the jaxb by which I can add this schema in xml file.

I want to jaxb because my original xml file size is very big and it contains so many tags.I also go through this site docs.oracle.com/javase/tutorial/jaxb/intro/custom.html but I did not get any idea.My xml file should be look like.

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18651
    
    8

You have already asked this question several times. Since you haven't received any answers yet, chances are that nobody reading these forums knows the answer.

Or here's another possibility: I strongly suspect that the answer is "No, you can't do that" but I'm not interested in doing the research to confirm that answer. Reading the documentation for a product in order to confirm that it can not do something is very difficult. I expect other people may feel the same way.
moin roy
Greenhorn

Joined: Mar 28, 2012
Posts: 15
@Paul Clapham I receive your answer on previous thread but you give me your reply by using dom4j which is dom parser but it can not be used in my present scenario because I have a large xml data,and which I asked in previous thread you did not give any reply please give me some idea.
Your example code totally make the xml file using dom4j and use getter setter method from jaxb.

I have an idea that if I generate large xml file with data using jaxb after making this abc.xml file now dom parser or other parser open this file and write the schema under <transaction> tag before <id> tag,but I am till now unable to put someting under <transaction> before <id>

Thanks for your previous reply on old thread it was a nice post,Please give me some positive reply I am waiting for that.

I try to do this using writing some code looks like
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18651
    
    8

arjun ray wrote:@Paul Clapham I receive your answer on previous thread but you give me your reply by using dom4j...


That wasn't my reply, that was somebody else's reply.
William P O'Sullivan
Ranch Hand

Joined: Mar 28, 2012
Posts: 859

That was me.

One technology may not handle everything.

Learn to mix-and-match to achieve your desired result.

Pat.
moin roy
Greenhorn

Joined: Mar 28, 2012
Posts: 15
@William P O'Sullivan yeap you are right did you see my post in this thread can you say that I am right or wrong?what I try to do is it a correct approach?please reply I am new in java please give some idea which can en-light me.
moin roy
Greenhorn

Joined: Mar 28, 2012
Posts: 15
@Paul Clapham oh I am really sorry I am new in forum so I made a mess,please don't mind.Thanks for your reply.
amit punekar
Ranch Hand

Joined: May 14, 2004
Posts: 514
Hello,
I went through the posts. What I am not able to understand is why you want to include the Schema as well in the generated XML.

Regards,
Amit
James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1030
    
    5

Totally agree with Amit here. Why do you want to add the schema to the XML that was generated from it?
moin roy
Greenhorn

Joined: Mar 28, 2012
Posts: 15
@James Boswell and amit punekar It is necessary to describe the whole thing ok lets start.Actually the application is make using C# on .NET 3.5,here after running the application it generate a transaction file(xml data+schema) looks like my demo xml file.Now this xml file automatically deleted from local machine and push to central database and store the xml data and if I corrupt any portion of this file it will not update the database for example if I delete the schema part of the generated file then it will unable to update the database.

Now question is why I want to make this file,basically I am a tester so I test this file properly update the database or not on different value or different configuration.It is very Time consuming that to ran the original application and generate the file.So I want to make this application by which I can generate this type of file in 100 times holding the same configuration or different.I want to make this using java because I know little bit of java.

Is it possible to using web service?because my original application is also use web service.

If web service is the main reason then please tell me how to use web service and how to access it if you give me some code snips then it will be helpful.

James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1030
    
    5

if I delete the schema part of the generated file then it will unable to update the database.


Why does updating the database depend upon the presence of the schema?
James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1030
    
    5

The standard for a schema reference within XML is to use the xsi:schemaLocation attribute. Never have I seen the need to inline the entire schema itself.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18651
    
    8

That was my impression too. What on earth is the point of including the schema inside the document it's supposed to validate? Wouldn't that make the document invalid? But then I googled for "inline schema" and got a lot of links which suggested to me that a lot of people want to do this, even though I think it's a totally weird thing to do. But then I don't work in an environment where we have to deal with schemas, so my opinion doesn't count for much.

arjun ray wrote:Now question is why I want to make this file,basically I am a tester so I test this file properly update the database or not on different value or different configuration.It is very Time consuming that to ran the original application and generate the file.So I want to make this application by which I can generate this type of file in 100 times holding the same configuration or different.I want to make this using java because I know little bit of java.


Looks like the idea that you know a little bit of Java, therefore you can write this code, is not working out. Most of the links I saw for "inline schema" were Microsoft-related, so maybe it's a weird Microsoft thing. That would explain why we don't have Java support for it. So here's a couple of options you could look at instead of that:

(1) Do the time-consuming step which generates the file (that would be the document containing its own schema, right?) but this time... Save a copy of the file. Use that copy for testing from now on.

(2) Get somebody else to do the programming, either in Java or in some other language, which produces your test file in a less time-consuming way.
moin roy
Greenhorn

Joined: Mar 28, 2012
Posts: 15
@Paul Clapham in my test application send the copied xml file to database but database will not updated because xml file contain have some unique number,if this number is entered previously then file will not be uploaded in database.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18651
    
    8

Looks like it's option (2) then.
moin roy
Greenhorn

Joined: Mar 28, 2012
Posts: 15
@Paul Clapham thanks for your escape solution.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to add xml schema within xml using jaxb