Hi Radu,

Thanks for your answer. I got there after playing the whole evening with
the api. I still have one question, If I use the compileXsd() method,
then I would have to iterate through my globalelements with a cursor
right? There's no way to dinamically get the Java-style classes
representing the schema types on runtime (i.e. classes like TryDocument
with getElement/getElementArray() for elements/attributes)?

thanks

El mié, 22-11-2006 a las 13:36 -0800, Radu Preotiuc-Pietro escribió:
> Javier,
> 
> If you are creating an xml editor, then you are correct that you can't
> expect to compile the Java classes for every Schema that your users
> have.
> 
> I think however that the approach of using .loadXsd() is not the best in
> your circumstances. (I know that the JavaDoc says "returns a unioned
> typeloader that is suitable for creating instances") Instead, I would
> use XmlBeans.compileXsd() which returns a SchemaTypeSystem instead of a
> SchemaTypeLoader. The difference is that SchemaTypeSystem has methods
> like .globalElements() which returns a list of all the declared global
> elements in that (set of) Schema(s).
> 
> Radu 
> 
> -----Original Message-----
> From: Jacob Danner 
> Sent: Wednesday, November 22, 2006 9:17 AM
> To: [email protected]
> Subject: RE: dynamic generation of xml files from an xsd
> 
> There is a utility to generate sample xml instances from XSD via a
> command line tool.
> Check out xmlbeans_trunk\bin\xsd2inst
> The main class is located in
> org.apache.xmlbeans.impl.xsd2inst.SchemaInstanceGenerator
> 
> I'm not sure this will help you terribly as it sounds like you want to
> know about all the global elements in an XSD programmatically. If this
> is the case, I might suggest using the XmlCursor APIs to find all
> elements that are children of to the schema element. E.g /schema/element
> 
> Best of luck,
> -Jacobd
> 
> -----Original Message-----
> From: Javier [mailto:[EMAIL PROTECTED]
> Sent: Wednesday, November 22, 2006 2:29 AM
> To: [email protected]
> Subject: dynamic generation of xml files from an xsd
> 
> Hi
> 
> I'm using Xmlbeans to create an xml editor. In this application you
> normally have an xsd to create xml files that conform to that schema.
> If I use xmlbeans at compile time there's no problem, I can generate the
> xmlbeans clases and interfaces and begin using them, but I now need to
> generate all this stuff at runtime, here's my initial code:
>         ...
>         // the schema
>         XmlObject xmlobj = XmlObject.Factory.parse(new
> File(xsdFileName));
>         XmlObject foo[] = { xmlobj };
>         // the schema types:
>         SchemaTypeLoader stl = XmlBeans.loadXsd(foo);
> 
> Now, my problem is that I don't know how to find the propiate root
> document type to generate a new XML that conforms to the schema. I've
> tried:
> 
>         SchemaType sType =
> stl.typeForClassname("com.name.try.TryDocument");
>         XmlOptions options = new XmlOptions();
>         XmlObject mydoc = stl.newInstance(sType, options);
> 
> with no success. The sType object is allways null and I don't know how
> to get my schema root element to generate an xml file. My schema looks
> something like this:
> 
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema";
>       xmlns="http://name.com/try";
>       targetNamespace="http://name.com/try";
>       elementFormDefault="qualified"
> attributeFormDefault="unqualified">
> 
>       <xs:element name="Try" type="TemplateType"/>
> 
>       <xs:complexType name="TemplateType">
>               <xs:sequence>
>                       <xs:element name="First" type="FirstType"/>
> 
> ...
> </xs:schema>
> 
> My understanding is that if I use static generation of xmlbeans i would
> have to search for a TryDocument interface and start from there.
> 
> Any help would be greatly appreciated.
> 
> Thanks
> 
> --
> Javier
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> _______________________________________________________________________
> Notice:  This email message, together with any attachments, may contain
> information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated
> entities,  that may be confidential,  proprietary,  copyrighted  and/or
> legally privileged, and is intended solely for the use of the individual
> or entity named in this message. If you are not the intended recipient,
> and have received this message in error, please immediately return this
> by email and then delete it.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to