Parsing XSD to generate xml instances

Discussion in 'Java' started by nethunter55@gmail.com, Apr 5, 2006.

  1. Guest

    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!
    , Apr 5, 2006
    #1
    1. Advertising

  2. Oliver Wong Guest

    <> wrote in message
    news:...
    > 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
    Oliver Wong, Apr 5, 2006
    #2
    1. Advertising

  3. Guest

    can u please lend me a sample code of what u have explained ?
    thanks
    , Apr 5, 2006
    #3
  4. James McGill Guest

    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.
    James McGill, Apr 5, 2006
    #4
  5. Oliver Wong Guest

    <> wrote in message
    news:...
    > 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
    Oliver Wong, Apr 5, 2006
    #5
  6. kanimozhi

    Joined:
    Sep 16, 2008
    Messages:
    1
    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..
    kanimozhi, Sep 16, 2008
    #6
  7. drrw

    Joined:
    Nov 6, 2008
    Messages:
    3
    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
    drrw, Nov 6, 2008
    #7
  8. drrw

    Joined:
    Nov 6, 2008
    Messages:
    3
    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
    drrw, Nov 6, 2008
    #8
  9. drrw

    Joined:
    Nov 6, 2008
    Messages:
    3
    The XSLT to ingest the XSD schema is gnarly BTW - that took over 4 months of work to create...!
    drrw, Nov 6, 2008
    #9
  10. bradv

    Joined:
    Apr 7, 2010
    Messages:
    1
    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
    bradv, Apr 7, 2010
    #10
  11. Paulo_ip

    Joined:
    Jun 23, 2010
    Messages:
    1
    Hi Bradv,

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

    Thans and Regards,
    Paulo
    Paulo_ip, Jun 23, 2010
    #11
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Markus
    Replies:
    1
    Views:
    1,080
    Markus
    Nov 22, 2005
  2. Matt
    Replies:
    3
    Views:
    37,203
    MKNDK
    Sep 11, 2008
  3. stiank81
    Replies:
    4
    Views:
    15,344
    stiank81
    Jun 26, 2005
  4. Rushi
    Replies:
    1
    Views:
    541
  5. Replies:
    0
    Views:
    551
Loading...

Share This Page