I want to write a java program in which I will read a XSD file and then using this I want to generate its corresponding XML file.
Please tell me how should I do it.
Tim Moores
Rancher
Joined: Sep 21, 2011
Posts: 2407
posted
0
XSD is XML. Or are you asking about how to create an XML document that conforms to that XSD? That's not possible, as there will generally be an infinite number of XML documents that conform to any given schema.
Tim Moores wrote:XSD is XML. Or are you asking about how to create an XML document that conforms to that XSD? That's not possible, as there will generally be an infinite number of XML documents that conform to any given schema.
Sorry i guess i did not framed my question properly..
Suppose if we have an XSD(taken from w3schools.com),I named it as MyXSD.xsd
Now in eclipse we can directly convert this XSD to generate its corresponding sample xml by right clicking it->Generate->select XML file.
I did the same for above XSD and got a new xml file say "file.xml" which is as below
this is a manual process.What I want is ;to generate an xml file from its XSD using my java program.is it possible..
Note: I don't want to use any tool..I want to do it using java program.
I have seen this question about a hundred times on various forums. Every time I see it I ask the question "Why would you want to do that?". So far I haven't received any good answers. So let me ask: Why would you want to do that?
Paul Clapham wrote:I have seen this question about a hundred times on various forums. Every time I see it I ask the question "Why would you want to do that?". So far I haven't received any good answers. So let me ask: Why would you want to do that?
I don't think that I posted this question to answer to anyone that why would I need to do it.If you know the answer please post it.A solution or guidance will be highly appreciated.
I do agree with Paul though. I see no reason why you would want to do this.
Thanks for link.
I want to do it cause I am working on something in which I have to know the depth of XML files.But I have only XSD files available and the depth of an XSD and XML is not same.
In case you all know any other way to determine the depth of XMl files conforming to a particular XSD then please tell me that also.But remember I have only XSDs available for this problem...
Let's start by guessing that the "depth" of an XML file is, when you consider it as a tree structure, the maximum value of the depth of all nodes. Where "depth" is the distance from a node to the root. (I don't see why you would care about that value, either, but whatever.)
So the schema might tell you that a "Thing" element could optionally contain a "Thing" element. In this case there could be any number of nested "Thing" elements, and you would have to scan the XML document and consider each node. But you can't tell anything about that from the schema, you would have to look at each individual document.
This whole thing sounds like a badly-thought-out mess. You have to find the "depth" of an XML document -- what for? And you aren't allowed to look at the documents to find their "depth" -- whose idea was that?
Jimmy Clark
Ranch Hand
Joined: Apr 16, 2008
Posts: 2187
posted
0
It seems like (with some individuals) there is confusion concerning the purpose and usage of XML-related tools. In past experience, individuals mistakenly think that XML instance files can be programmatically created using the XML Schema which defines the XML-based language. For any language with a mild range of complexity, this is not possible.
The fact that some programming APIs use schemas for creating classes and objects derived from information in the schema most likely contributes to confusion and misunderstanding. XML Schemas and XML Document Type Definitions are for creating a XML-based markup language and for "validation", i.e. parsing, of documents. They are not used for "creating" the documents. In other words, creating an XML-based markup language (with a XML Schema or DTD) and creating related documents/instances (with programming API) are not the same.
Creation of XML-based documents should be based on specific written requirements, not generalized structures specified in schema or DTD.
Aside, there are a bunch of areas to get confused (unfortunately, it happens often.) Validation using XML DTD was good enough in my opinion. It helped separate document validation and processing. XML Schema muddied the waters quite a bit and helps foster areas of confusion and misunderstanding.
g tsuji
Ranch Hand
Joined: Jan 18, 2011
Posts: 359
1
posted
0
I am actually quite disappointed on how this thread turns into.
The only problem of the original question asked is that it is asking too much and showing too little his own competence so that people can at least anchor a starting point to help. It is too involved a question. It is not simple, it is advanced that is why so many utilities have tools with command line for that purpose. If it is done is all generality correctly, you've to understand the schema recommendation inside-out. That alone is not declarative, by verbiage. The question in itself is 100% meaningful. Existence is not something to be taken upon lightly. But, I am not saying everybody should take it seriously - each for his own inclination, though it won't helo you much making bread and butter at the end.
Apart from the original question, I just want to record that I have strong disagreement with some opinions expressed so as to let other readers (present or future) know those opinions are in fact quite awkward, and/or in fact quite misleading in the least.
Tim Moores
Rancher
Joined: Sep 21, 2011
Posts: 2407
posted
0
g tsuji wrote:Apart from the original question, I just want to record that I have strong disagreement with some opinions expressed so as to let other readers (present or future) know those opinions are in fact quite awkward, and/or in fact quite misleading in the least.
Why don't you point out what, specifically, you take issue with?
g tsuji
Ranch Hand
Joined: Jan 18, 2011
Posts: 359
1
posted
0
>Why don't you point out what, specifically, you take issue with? That's what I did on the issue on-topic. For those not really on-topic and from respectable members, I tell you, it is very distressing - it is no fun. But I draw no pleasure to be felt like grilling others nor stuck my head out for being grilled. However, as I were already doing too often holding back, if everybody keeps silent about, it makes the forum look bad, again to my opinion only. I let those who have long history of posting here, as insiders, to manage that side.
I do agree with Paul though. I see no reason why you would want to do this.
Thanks james,link provided by you really helped me..:)
janusz lece
Greenhorn
Joined: Jul 06, 2012
Posts: 1
posted
0
hello Sunni,
could you provide more details how did you solve this problem?
Nolan Brassard
Greenhorn
Joined: Feb 14, 2013
Posts: 2
posted
0
I can explain the reason I need to accomplish this. I am a developer for a company that supplies tools for higher education for managing and transferring large amounts of data. Sometimes the transfers consist of uploading a doc, parsing the data, and updating it the correct student/staff/etc. Well we now support the ability to transfer data from xml files. In order to do that they need to use our tool to build the definition of the xml file we will be reading. We let them pick a sample xml file and choose which nodes/attributes to include in the definition. Well now they want the ability to build those definitions from xsd files. In order to do that we need to be able to read xsd files so we can display the available nodes/attributes in the tree panel as we do with sample xml files. Well I figured instead of reinventing what we already wrote..lets convert the xsd to a sample xml with default values even if its just "" for every single value.
Do you understand the reason? Obviously I could explain it with better detail but its also Proprietary so attempted to do it without going to far in. If anyone knows of a way to do this please let me know.
I was able to find a solution else where and implemented it with ease into my product. Much more bearable then any of the other suggestions I've found.