Hi Bikash,

Comments below...

Bikash Behera wrote:
> 
> Hi,
> 
> We are using Castor API for marshaling java objects.
> It is pretty cool. There is something I am trying to do.
> I was wondering if you already have support for this.
> 
> We generate the XML document for a Java object through runtime introspection
> of Castor XML.
> Also we generate the Java Object back from an XML document that might
> represent it.
> 
> We need to know the structure and format of the XML document generated for a
> given Java object.
> The ideal thing would be to express this an an XML Schema.
> 
> Given a java class we need to generate an XML Schema that captures the
> structure of the
> XML document that will be generated corresponding to an object of the given
> java class.
> 
> I was looking into the API to see if there is any direct support for this. I
> did not find any.

Well...currently in the CVS version, you can create an XML Schema based
off an XML instance document. (see
org.exolab.castor.xml.schema.util.XMLInstance2Schema)

It's not perfect, but it's a good start at seeing the structure.

So..you can generate your XML...and then run it through
XMLInstance2Schema to see the structure of that particular XML instance.

It's not the ideal solution, since the Schema generated is only based of
one instance, but you can tweak it if necessary.

> Please let me know if I missed something. In the absence of such support I
> was intending
> to generate the XML Schema from the "XMLClassDescriptor" that "Introspector"
> provides.

Yes, this is a good idea because the Schema generated would support all
instances of the object/xml model.

> I was planning to interate through all the "XMLFieldDescriptor"s of the
> "XMLClassDescriptors"
> and add them as ElementDecl to the XML Schema.

In most cases ElementDecl or AttributeDecl would work. If you just treat
it as ElementDecl it won't always work. For example...the introspector
can choose between elements of attributes for simple types such as
integers or booleans, etc. This is configurable, so getting the node
type from the descriptor is probably a good idea. 

> Please let me know if I am on
> the right track.

Yes, this is the right track.

Feel free to look at the  code already available in:

org.exolab.castor.xml.schema.util.XMLInstance2Schema

I recommend looking at this code because there are some known bugs with
the Schema object model (such as being able to create a ComplexType and
adding ElementDecls directly to it, instead of first creating and adding
a Group, and then adding the ElementDecls to the Group.) that stem from
supporting past XML Schema drafts.

Thanks,

--Keith

----------------------------------------------------------- 
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-dev

Reply via email to