Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Parsing XSD to generate xml instances

Reply
Thread Tools

Parsing XSD to generate xml instances

 
 
nethunter55@gmail.com
Guest
Posts: n/a
 
      04-05-2006
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!

 
Reply With Quote
 
 
 
 
Oliver Wong
Guest
Posts: n/a
 
      04-05-2006
<> wrote in message
news: oups.com...
> 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

 
Reply With Quote
 
 
 
 
nethunter55@gmail.com
Guest
Posts: n/a
 
      04-05-2006
can u please lend me a sample code of what u have explained ?
thanks

 
Reply With Quote
 
James McGill
Guest
Posts: n/a
 
      04-05-2006
On Wed, 2006-04-05 at 19:21 +0000, Oliver Wong wrote:
> 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.

 
Reply With Quote
 
Oliver Wong
Guest
Posts: n/a
 
      04-05-2006
<> wrote in message
news: ups.com...
> 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

 
Reply With Quote
 
kanimozhi kanimozhi is offline
Junior Member
Join Date: Sep 2008
Posts: 1
 
      09-16-2008
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..
 
Reply With Quote
 
drrw drrw is offline
Junior Member
Join Date: Nov 2008
Posts: 3
 
      11-06-2008
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
 
Reply With Quote
 
drrw drrw is offline
Junior Member
Join Date: Nov 2008
Posts: 3
 
      11-06-2008
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
 
Reply With Quote
 
drrw drrw is offline
Junior Member
Join Date: Nov 2008
Posts: 3
 
      11-06-2008
The XSLT to ingest the XSD schema is gnarly BTW - that took over 4 months of work to create...!
 
Reply With Quote
 
bradv bradv is offline
Junior Member
Join Date: Apr 2010
Posts: 1
 
      04-07-2010
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
convert XML to XSD? or DTD to XSD? Matt XML 3 09-11-2008 12:40 PM
Overriding XSD locations when validating an xml document with multiple xsd references anthony@jayasekera.net Java 0 08-25-2006 11:22 AM
Validation of XSD (XML Schema) against XSD Rushi XML 1 12-09-2005 08:12 AM
XML + XSD: Is it possible to get all errors against the XSD? Markus Java 1 11-22-2005 02:53 PM
XML schema - Make xsd include another xsd stiank81 XML 4 06-26-2005 05:11 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57