Dynamic generation of XML object hierarchy using schema

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Dynamic generation of XML object hierarchy using schema

jgagnon
I am working on a project where we are trying to dynamically generate XML instances, using the information gleaned from a defining XML schema.  The instances will represent test cases for a given "message" type.

I've experimented with the XMLBeans schema type system to get useful information about the types defined in the schema, such as the structure (sequences, choices, etc.), min/max occurs and various restrictions (enumerations, patterns, etc.). This information will be used to determine what types of test cases will be generated for a given message element.

I'm at the point where I'd like to use the XMLBeans Java API to programmatically generate XML document instances. Of course, I would need to compile the schema to generate a Java library of classes that represent the Java form of the message types (and supporting types).

What I don't know is how to dynamically use the generated API to create an object hierarchy representing a test case.  The hierarchy would represent a message instance (which may or may not be valid or complete based on the test case), with element content populated with test data.

I cannot seem to find the information from the schema type system that would allow me to "bridge" between the schema information and the specific generated API classes that would need to be used to generate the object hierarchy.

I assume if this information is available, I would then need to use reflection to create the objects and set their values and attributes.

Does anyone have suggestions?
Reply | Threaded
Open this post in threaded view
|

Re: Dynamic generation of XML object hierarchy using schema

jerry.sy
look at the XmlCursor api. You can use it to create an xml document.

On 5/6/2014 8:19 AM, jgagnon wrote:

> I am working on a project where we are trying to dynamically generate XML
> instances, using the information gleaned from a defining XML schema.  The
> instances will represent test cases for a given "message" type.
>
> I've experimented with the XMLBeans schema type system to get useful
> information about the types defined in the schema, such as the structure
> (sequences, choices, etc.), min/max occurs and various restrictions
> (enumerations, patterns, etc.). This information will be used to determine
> what types of test cases will be generated for a given message element.
>
> I'm at the point where I'd like to use the XMLBeans Java API to
> programmatically generate XML document instances. Of course, I would need to
> compile the schema to generate a Java library of classes that represent the
> Java form of the message types (and supporting types).
>
> What I don't know is how to dynamically use the generated API to create an
> object hierarchy representing a test case.  The hierarchy would represent a
> message instance (which may or may not be valid or complete based on the
> test case), with element content populated with test data.
>
> I cannot seem to find the information from the schema type system that would
> allow me to "bridge" between the schema information and the specific
> generated API classes that would need to be used to generate the object
> hierarchy.
>
> I assume if this information is available, I would then need to use
> reflection to create the objects and set their values and attributes.
>
> Does anyone have suggestions?
>
>
>
> --
> View this message in context: http://xmlbeans.996285.n3.nabble.com/Dynamic-generation-of-XML-object-hierarchy-using-schema-tp7501.html
> Sent from the XMLBeans User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Dynamic generation of XML object hierarchy using schema

Cezar Andrei-3
In reply to this post by jgagnon
Joseph,

Best way to learn for what you need to is to look at the implementation of xsd2inst tool:
http://svn.apache.org/viewvc/xmlbeans/trunk/src/tools/org/apache/xmlbeans/impl/xsd2inst/SchemaInstanceGenerator.java?view=markup

Cezar


On May 6, 2014, at 11:19 AM, jgagnon <[hidden email]> wrote:

> I am working on a project where we are trying to dynamically generate XML
> instances, using the information gleaned from a defining XML schema.  The
> instances will represent test cases for a given "message" type.
>
> I've experimented with the XMLBeans schema type system to get useful
> information about the types defined in the schema, such as the structure
> (sequences, choices, etc.), min/max occurs and various restrictions
> (enumerations, patterns, etc.). This information will be used to determine
> what types of test cases will be generated for a given message element.
>
> I'm at the point where I'd like to use the XMLBeans Java API to
> programmatically generate XML document instances. Of course, I would need to
> compile the schema to generate a Java library of classes that represent the
> Java form of the message types (and supporting types).
>
> What I don't know is how to dynamically use the generated API to create an
> object hierarchy representing a test case.  The hierarchy would represent a
> message instance (which may or may not be valid or complete based on the
> test case), with element content populated with test data.
>
> I cannot seem to find the information from the schema type system that would
> allow me to "bridge" between the schema information and the specific
> generated API classes that would need to be used to generate the object
> hierarchy.
>
> I assume if this information is available, I would then need to use
> reflection to create the objects and set their values and attributes.
>
> Does anyone have suggestions?
>
>
>
> --
> View this message in context: http://xmlbeans.996285.n3.nabble.com/Dynamic-generation-of-XML-object-hierarchy-using-schema-tp7501.html
> Sent from the XMLBeans User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Dynamic generation of XML object hierarchy using schema

jgagnon
In reply to this post by jerry.sy
I assume that using the XmlCursor to build a document object hierarchy will not make any use of the schema generated API?