Parsing XSD to generate xml instances

N

nethunter55

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!
 
O

Oliver Wong

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.

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.

- Oliver
 
J

James McGill

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.

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.
 
O

Oliver Wong

can u please lend me a sample code of what u have explained ?
thanks

Er... well, I could give you pseudocode... Anything more than that, and
you'd have to pay me.

<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>

- Oliver
 
Joined
Sep 16, 2008
Messages
1
Reaction score
0
Hi

Have u got the idea to parse the xsd file..am also working on a similar project..can u tell me the idea u used ?

Thanks in advance..
 
Joined
Nov 6, 2008
Messages
3
Reaction score
0
Generating XML test cases - jCAM toolset

You can easily ingest your XSD schema and create realistic XML test cases using the tools provided in the jCAM toolset. It uses a mix of Java, Eclipse and XSLT / Saxon to achieve this for you - and is fully configurable at XML level - plus is using the OASIS CAM standard.

You can download on SourceForge.net camprocessor, and the tutorial is available from the new section or from oasis-open.org committees - CAM - content assembly mechanism.

Enjoy, DW
 
Joined
Nov 6, 2008
Messages
3
Reaction score
0
I just noticed folks were asking for options too - should point out the XML test case outputting is full configurable - All, random, none, etc - to create realistic examples.

Google search for the tutorial "XSD and jCAM tutorial.pdf"

DW
 
Joined
Nov 6, 2008
Messages
3
Reaction score
0
The XSLT to ingest the XSD schema is gnarly BTW - that took over 4 months of work to create...!
 
Joined
Apr 7, 2010
Messages
1
Reaction score
0
attributes in xsom

When parsing a XSD file through XSOM, is it posible to find attributes that exist inside elements, such as the example given below?

<xsd:schema>
<xsd:element name="Bird">
<xsd:complexType>
<xsd:attribute name="small" type="xsd:string" use="required"></xsd:attribute>
</xsd:complexType>
</xsd:element>
</xsd:schema>

Thanks
 
Joined
Jun 23, 2010
Messages
1
Reaction score
0
Hi Bradv,

Did you manage to parse a complex type similar to the one you showed ?

Thans and Regards,
Paulo
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top