Parsing XSD to generate xml instances
Hello...
Is it possible to parse (or rather read) an xsd file and depending on the constraints in the xsd...develop a java code to generate xml instances confirming to the xsd ?
I am working on something called "template based code generation" where in my template is an xsd file which i have to read and create xml instances confirming to the xsd . After that these xml instances would be used as data inputs to another code which will be used to generating test cases.
please help!
Re: Parsing XSD to generate xml instances
I think it is always possible, given a valid XSD, to generate an XML that conforms to that XSD, and I think it may even be feasible (perhaps even trivial?) to implement a program to do this for you. However, I'm not sure why this would be useful. E.g. my implementation would always generate the minimum XML possible. If the empty document is legal, that's what it will generate.
Re: Parsing XSD to generate xml instances
Can u please lend me a sample code of what u have explained ?
thanks.
Re: Parsing XSD to generate xml instances
XMLSpy does a pretty good job of this. It even gives you a decent amount of control over the specimen document that it produces. It can certainly be useful to be able to generate document from schema, although, the range of values that you need for testing is generally more than you get from this.
Re: Parsing XSD to generate xml instances
Er... well, I could give you pseudocode... Anything more than that, and
you'd have to pay me.
Code:
<pseudocode>
generateBasicNode(someNode) {
emit "<";
emit someNode.name;
/*handle the attributes in the obvious way*/
emit ">";
for each child in someNode.children {
generateNode(child)
}
emit "</";
emit someNode.name;
emit ">";
}
generateOptionalNode(someNode) {
/*Don't emit optional nodes, 'cause they're optional*/
}
generateNodeSequence(someSequence) {
for each node in someSequence {
generateNode(node);
}
}
//etc.
</pseudocode>