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: 2329
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: 2159
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: 225
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: 2329
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: 225
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.