Re: Converting from using scomp to SchemaTypeLoader.parse(...)
badger mailinglist <[email protected]> Tue, 15 Jan 2013 13:55:34 +0000
| Newsgroups | gmane.text.xml.xmlbeans.user |
|---|---|
| Message-ID | <CAF7=XdgwV6B6wjuJZiQ-4tY4BRc1F78uNi47PskAeUMtPZYC6Q@mail.gmail.com> |
--e89a8fb20078a67d6f04d3541da5 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable Thanks Paul and Jacob, I guess I didn't quite read through the tutorials far enough. It's all working now I'm *actually* compiling the xsd. Thanks again, Badger. On 14 January 2013 23:27, Paul Gillen <[email protected]> wrote: > Boy, I wish I got paid for this crap.**** > > ** ** > > Full answer here: > http://www.oracle.com/technetwork/articles/entarch/incremental-compilatio= n-xmlbeans-089127.html > **** > > ** ** > > In your first example you had compiled your schema and created an object > to describe parsed XML.**** > > ** ** > > In you second example you parsed the XSD, which is after all XML, and, > surprise, it=92s described by W3C XSD.**** > > ** ** > > What you want to do, and I would be interested in hearing why, is to > compile the XSD on the fly.**** > > ** ** > > The output of the example below is:**** > > D=3DTestSchema**** > > D=3Dschema@http://www.w3.org/2001/XMLSchema**** > > D=3DTestSchema**** > > where the first is your first example, the second is your second example, > and the third is from compiling the XSD on the fly.**** > > ** ** > > Hope this helps.**** > > ** ** > > Cheers,**** > > Paul**** > > ** ** > > *package* com.riveralph;**** > > ** ** > > *import* java.io.File;**** > > ** ** > > *import* noNamespace.TestSchemaDocument;**** > > ** ** > > *import* org.apache.xmlbeans.SchemaTypeLoader;**** > > *import* org.apache.xmlbeans.SchemaTypeSystem;**** > > *import* org.apache.xmlbeans.XmlBeans;**** > > *import* org.apache.xmlbeans.XmlObject;**** > > *import* org.apache.xmlbeans.XmlOptions;**** > > *import* org.apache.xmlbeans.impl.xb.xsdschema.SchemaDocument;**** > > ** ** > > *public* *class* TestSchema {**** > > *public* *static* *void* main(String[] args) *throws* Exception {**= * > * > > TestSchema ts =3D *new* TestSchema();**** > > ts.go(args);**** > > }**** > > ** ** > > *private* *void* go(String[] args) *throws* Exception {**** > > {**** > > XmlObject instance =3D TestSchemaDocument.Factory.* > newInstance*(*new* XmlOptions());**** > > System.*out*.println(instance.schemaType());**** > > }**** > > ** ** > > {**** > > SchemaTypeLoader loader =3D XmlBeans.* > typeLoaderForClassLoader*(SchemaDocument.*class*.getClassLoader());**** > > XmlObject instance =3D loader.parse(*new* File( > "xsd/testschema.xsd"),*null*, *new* XmlOptions());**** > > System.*out*.println(instance.schemaType());**** > > }**** > > ** ** > > {**** > > XmlObject[] schemaObj =3D *new* XmlObject[] { > XmlObject.Factory.*parse*(*new* File("xsd/testschema.xsd"))};**** > > SchemaTypeSystem schemaTypeObj =3D XmlBeans.* > compileXmlBeans*(*null*, *null*, schemaObj, *null*, *null*, *null*, *null= * > );**** > > XmlObject instance =3D > schemaTypeObj.newInstance(schemaTypeObj.documentTypes()[0], *null*);**** > > System.*out*.println(instance.schemaType());**** > > }**** > > ** ** > > }**** > > }**** > > ** ** > > ** ** > > *From:* badger mailinglist [mailto:[email protected]] > *Sent:* Monday, January 14, 2013 6:35 AM > *To:* [email protected] > *Subject:* Re: Converting from using scomp to SchemaTypeLoader.parse(...)= * > *** > > ** ** > > Ok, so I guess no one has ever tried this. > > Maybe there's a simpler question: > > If I use the SchemaTypeLoader.parse method, I struggle to get information > about the schema from that object. I want to iterate through the attribut= es > and elements declared in the XSD I'm parsing, but all I seem to get is w3 > xml schema stuff. Am I trying to do something that isn't supported, or am= I > just doing it wrong? > > Any help much appreciated, > > Cheers, > > Badger.**** > > On 8 January 2013 15:42, badger mailinglist <[email protected]= m> > wrote:**** > > Hi, > > Currently, I take some XSDs (see below for example), generate classes for > them (with scomp -out generatedClasses.jar testschema.xsd), then use thos= e > classes in code with some like: > final XmlObject instance =3D > TestSchemaDocument.Factory.newInstance(xmlOptions); > > This process now needs to be a bit more dynamic, so I'm trying to use > something more like the following: > > final SchemaTypeLoader loader =3D > XmlBeans.typeLoaderForClassLoader(SchemaDocument.class.getClassLoader()); > XmlOptions xmlOptions =3D new XmlOptions(); > final XmlObject fileParsedInstance =3D loader.parse(new > File("C:\\testschema.xsd"), null, new XmlOptions()); > > > However, I would expect the XmlObject returned in both cases to be the > same. However, if I recursively iterate through the properties of these t= wo > objects, I get different results i.e. calling > instance.schemaType().getProperties() gets different results in each of t= he > cases. > For the instance loaded from the class the getProperties() method returns > one element with type 'TestSchema', which itself returns one element with > type 'TestType' and so on as you recur. > For the instance loaded directly from the xsd file the properties are all > things like E=3Drestriction|D=3Drestriction@http://www.w3.org/2001/XMLSch= ema, > which has a property T=3DlocalSimpleType@http://www.w3.org/2001/XMLSchema= , > which has a property 'restriction' and so on infinitely. > > I've assumed that these two methods of loading the schema would do the > same thing, but it looks like I'm wrong, can someone point me at the meth= od > call I need to make to load from the file properly? I'm using XmlBeans > 2.5.0. > > Thanks! > > > Example xsd I'm testing this with: > > <?xml version=3D"1.0" encoding=3D"utf-8"?> > <xs:schema attributeFormDefault=3D"unqualified" > elementFormDefault=3D"qualified" xmlns:xs=3D"http://www.w3.org/2001/XMLSc= hema > "> > > <xs:element name=3D"TestSchema" type=3D"TestType" /> > > <xs:complexType name=3D"TestComplexType"> > <xs:sequence> > <xs:element type=3D"xs:string" name=3D"thing" /> > </xs:sequence> > </xs:complexType> > > <xs:complexType name=3D"TestType"> > <xs:sequence> > <xs:element type=3D"TestComplexType" name=3D"TestComplex" > maxOccurs=3D"unbounded" minOccurs=3D"0" /> > </xs:sequence> > </xs:complexType> > > </xs:schema>**** > > ** ** > --e89a8fb20078a67d6f04d3541da5 Content-Type: text/html; charset=windows-1252 Content-Transfer-Encoding: quoted-printable Thanks Paul and Jacob, I guess I didn't quite read through the tutorial= s far enough. It's all working now I'm *actually* compiling the xsd= .<br><br>Thanks again,<br><br>Badger.<br><br><br><div class=3D"gmail_quote"= > On 14 January 2013 23:27, Paul Gillen <span dir=3D"ltr"><<a href=3D"mail= to:[email protected]" target=3D"_blank">[email protected]</a>&g= t;</span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0= .8ex;border-left:1px #ccc solid;padding-left:1ex"> <div link=3D"blue" vlink=3D"purple" lang=3D"EN-US"><div><p class=3D"MsoNorm= al"><span style=3D"font-size:11.0pt;font-family:"Calibri","s= ans-serif";color:#1f497d">Boy, I wish I got paid for this crap.<u></u>= <u></u></span></p> <p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca= libri","sans-serif";color:#1f497d"><u></u>=A0<u></u></span><= /p><p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"= ;Calibri","sans-serif";color:#1f497d">Full answer here: <a h= ref=3D"http://www.oracle.com/technetwork/articles/entarch/incremental-compi= lation-xmlbeans-089127.html" target=3D"_blank">http://www.oracle.com/techne= twork/articles/entarch/incremental-compilation-xmlbeans-089127.html</a><u><= /u><u></u></span></p> <p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca= libri","sans-serif";color:#1f497d"><u></u>=A0<u></u></span><= /p><p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"= ;Calibri","sans-serif";color:#1f497d">In your first example = you had compiled your schema and created an object to describe parsed XML.<= u></u><u></u></span></p> <p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca= libri","sans-serif";color:#1f497d"><u></u>=A0<u></u></span><= /p><p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"= ;Calibri","sans-serif";color:#1f497d">In you second example = you parsed the XSD, which is after all XML, and, surprise, it=92s described= by W3C XSD.<u></u><u></u></span></p> <p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca= libri","sans-serif";color:#1f497d"><u></u>=A0<u></u></span><= /p><p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"= ;Calibri","sans-serif";color:#1f497d">What you want to do, a= nd I would be interested in hearing why, is to compile the XSD on the fly.<= u></u><u></u></span></p> <p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca= libri","sans-serif";color:#1f497d"><u></u>=A0<u></u></span><= /p><p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"= ;Calibri","sans-serif";color:#1f497d">The output of the exam= ple below is:<u></u><u></u></span></p> <p class=3D"MsoNormal" style=3D"margin-left:.5in;text-autospace:none"><span= style=3D"font-size:10.0pt;font-family:"Courier New"">D=3DTestSch= ema</span><span style=3D"font-size:10.0pt;font-family:"Courier New&quo= t;"><u></u><u></u></span></p> <p class=3D"MsoNormal" style=3D"margin-left:.5in;text-autospace:none"><span= style=3D"font-size:10.0pt;font-family:"Courier New"">D=3Dschema@= <a href=3D"http://www.w3.org/2001/XMLSchema" target=3D"_blank">http://www.w= 3.org/2001/XMLSchema</a></span><span style=3D"font-size:10.0pt;font-family:= "Courier New""><u></u><u></u></span></p> <p class=3D"MsoNormal" style=3D"margin-left:.5in"><span style=3D"font-size:= 10.0pt;font-family:"Courier New"">D=3DTestSchema<u></u><u></u></s= pan></p><p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:= "Calibri","sans-serif";color:#1f497d">where the first i= s your first example, the second is your second example, and the third is f= rom compiling the XSD on the fly.<u></u><u></u></span></p> <p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca= libri","sans-serif";color:#1f497d"><u></u>=A0<u></u></span><= /p><p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"= ;Calibri","sans-serif";color:#1f497d">Hope this helps.<u></u= ><u></u></span></p> <p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca= libri","sans-serif";color:#1f497d"><u></u>=A0<u></u></span><= /p><p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"= ;Calibri","sans-serif";color:#1f497d">Cheers,<u></u><u></u><= /span></p> <p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca= libri","sans-serif";color:#1f497d">Paul<u></u><u></u></span>= </p><p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:&quo= t;Calibri","sans-serif";color:#1f497d"><u></u>=A0<u></u></sp= an></p> <p class=3D"MsoNormal" style=3D"text-autospace:none"><b><span style=3D"font= -size:10.0pt;font-family:"Courier New";color:#7f0055">package</sp= an></b><span style=3D"font-size:10.0pt;font-family:"Courier New""= > com.riveralph;</span><span style=3D"font-size:10.0pt;font-family:"Co= urier New""><u></u><u></u></span></p> <p class=3D"MsoNormal" style=3D"text-autospace:none"><span style=3D"font-si= ze:10.0pt;font-family:"Courier New""><u></u>=A0<u></u></span></p>= <p class=3D"MsoNormal" style=3D"text-autospace:none"><b><span style=3D"font= -size:10.0pt;font-family:"Courier New";color:#7f0055">import</spa= n></b><span style=3D"font-size:10.0pt;font-family:"Courier New"">= java.io.File;</span><span style=3D"font-size:10.0pt;font-family:"Cour= ier New""><u></u><u></u></span></p> <p class=3D"MsoNormal" style=3D"text-autospace:none"><span style=3D"font-si= ze:10.0pt;font-family:"Courier New""><u></u>=A0<u></u></span></p>= <p class=3D"MsoNormal" style=3D"text-autospace:none"><b><span style=3D"font= -size:10.0pt;font-family:"Courier New";color:#7f0055">import</spa= n></b><span style=3D"font-size:10.0pt;font-family:"Courier New"">= noNamespace.TestSchemaDocument;</span><span style=3D"font-size:10.0pt;font= -family:"Courier New""><u></u><u></u></span></p> <p class=3D"MsoNormal" style=3D"text-autospace:none"><span style=3D"font-si= ze:10.0pt;font-family:"Courier New""><u></u>=A0<u></u></span></p>= <p class=3D"MsoNormal" style=3D"text-autospace:none"><b><span style=3D"font= -size:10.0pt;font-family:"Courier New";color:#7f0055">import</spa= n></b><span style=3D"font-size:10.0pt;font-family:"Courier New"">= org.apache.xmlbeans.SchemaTypeLoader;</span><span style=3D"font-size:10.0p= t;font-family:"Courier New""><u></u><u></u></span></p> <p class=3D"MsoNormal" style=3D"text-autospace:none"><b><span style=3D"font= -size:10.0pt;font-family:"Courier New";color:#7f0055">import</spa= n></b><span style=3D"font-size:10.0pt;font-family:"Courier New"">= org.apache.xmlbeans.SchemaTypeSystem;</span><span style=3D"font-size:10.0p= t;font-family:"Courier New""><u></u><u></u></span></p> <p class=3D"MsoNormal" style=3D"text-autospace:none"><b><span style=3D"font= -size:10.0pt;font-family:"Courier New";color:#7f0055">import</spa= n></b><span style=3D"font-size:10.0pt;font-family:"Courier New"">= org.apache.xmlbeans.XmlBeans;</span><span style=3D"font-size:10.0pt;font-f= amily:"Courier New""><u></u><u></u></span></p> <p class=3D"MsoNormal" style=3D"text-autospace:none"><b><span style=3D"font= -size:10.0pt;font-family:"Courier New";color:#7f0055">import</spa= n></b><span style=3D"font-size:10.0pt;font-family:"Courier New"">= org.apache.xmlbeans.XmlObject;</span><span style=3D"font-size:10.0pt;font-= family:"Courier New""><u></u><u></u></span></p> <p class=3D"MsoNormal" style=3D"text-autospace:none"><b><span style=3D"font= -size:10.0pt;font-family:"Courier New";color:#7f0055">import</spa= n></b><span style=3D"font-size:10.0pt;font-family:"Courier New"">= org.apache.xmlbeans.XmlOptions;</span><span style=3D"font-size:10.0pt;font= -family:"Courier New""><u></u><u></u></span></p> <p class=3D"MsoNormal" style=3D"text-autospace:none"><b><span style=3D"font= -size:10.0pt;font-family:"Courier New";color:#7f0055">import</spa= n></b><span style=3D"font-size:10.0pt;font-family:"Courier New"">= org.apache.xmlbeans.impl.xb.xsdschema.SchemaDocument;</span><span style=3D= "font-size:10.0pt;font-family:"Courier New""><u></u><u></u></span= ></p> <p class=3D"MsoNormal" style=3D"text-autospace:none"><span style=3D"font-si= ze:10.0pt;font-family:"Courier New""><u></u>=A0<u></u></span></p>= <p class=3D"MsoNormal" style=3D"text-autospace:none"><b><span style=3D"font= -size:10.0pt;font-family:"Courier New";color:#7f0055">public</spa= n></b><span style=3D"font-size:10.0pt;font-family:"Courier New"">= </span><b><span style=3D"font-size:10.0pt;font-family:"Courier New&qu= ot;;color:#7f0055">class</span></b><span style=3D"font-size:10.0pt;font-fam= ily:"Courier New""> TestSchema {</span><span style=3D"font-size:1= 0.0pt;font-family:"Courier New""><u></u><u></u></span></p> <p class=3D"MsoNormal" style=3D"text-autospace:none"><span style=3D"font-si= ze:10.0pt;font-family:"Courier New"">=A0=A0=A0=A0=A0 </span><b><s= pan style=3D"font-size:10.0pt;font-family:"Courier New";color:#7f= 0055">public</span></b><span style=3D"font-size:10.0pt;font-family:"Co= urier New""> </span><b><span style=3D"font-size:10.0pt;font-family:&qu= ot;Courier New";color:#7f0055">static</span></b><span style=3D"font-si= ze:10.0pt;font-family:"Courier New""> </span><b><span style=3D"fo= nt-size:10.0pt;font-family:"Courier New";color:#7f0055">void</spa= n></b><span style=3D"font-size:10.0pt;font-family:"Courier New"">= main(String[] args) </span><b><span style=3D"font-size:10.0pt;font-family:= "Courier New";color:#7f0055">throws</span></b><span style=3D"font= -size:10.0pt;font-family:"Courier New""> Exception {</span><span = style=3D"font-size:10.0pt;font-family:"Courier New""><u></u><u></= u></span></p> <p class=3D"MsoNormal" style=3D"text-autospace:none"><span style=3D"font-si= ze:10.0pt;font-family:"Courier New"">=A0=A0=A0=A0=A0 =A0=A0=A0=A0= =A0 TestSchema ts =3D </span><b><span style=3D"font-size:10.0pt;font-family= :"Courier New";color:#7f0055">new</span></b><span style=3D"font-s= ize:10.0pt;font-family:"Courier New""> TestSchema();</span><span = style=3D"font-size:10.0pt;font-family:"Courier New""><u></u><u></= u></span></p> <p class=3D"MsoNormal" style=3D"text-autospace:none"><span style=3D"font-si= ze:10.0pt;font-family:"Courier New"">=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0 ts.go(args);</span><span style=3D"font-size:10.0pt;font-family:"= ;Courier New""><u></u><u></u></span></p> <p class=3D"MsoNormal" style=3D"text-autospace:none"><span style=3D"font-si= ze:10.0pt;font-family:"Courier New"">=A0=A0=A0=A0=A0 }</span><spa= n style=3D"font-size:10.0pt;font-family:"Courier New""><u></u><u>= </u></span></p> <p class=3D"MsoNormal" style=3D"text-autospace:none"><span style=3D"font-si= ze:10.0pt;font-family:"Courier New""><u></u>=A0<u></u></span></p>= <p class=3D"MsoNormal" style=3D"text-autospace:none"><span style=3D"font-si= ze:10.0pt;font-family:"Courier New"">=A0=A0=A0=A0=A0 </span><b><s= pan style=3D"font-size:10.0pt;font-family:"Courier New";color:#7f= 0055">private</span></b><span style=3D"font-size:10.0pt;font-family:"C= ourier New""> </span><b><span style=3D"font-size:10.0pt;font-family:&q= uot;Courier New";color:#7f0055">void</span></b><span style=3D"font-siz= e:10.0pt;font-family:"Courier New""> go(String[] args) </span><b>= <span style=3D"font-size:10.0pt;font-family:"Courier New";color:#= 7f0055">throws</span></b><span style=3D"font-size:10.0pt;font-family:"= Courier New""> Exception {</span><span style=3D"font-size:10.0pt;font-= family:"Courier New""><u></u><u></u></span></p> <p class=3D"MsoNormal" style=3D"text-autospace:none"><span style=3D"font-si= ze:10.0pt;font-family:"Courier New"">=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0 {</span><span style=3D"font-size:10.0pt;font-family:"Courier Ne= w""><u></u><u></u></span></p> <p class=3D"MsoNormal" style=3D"text-autospace:none"><span style=3D"font-si= ze:10.0pt;font-family:"Courier New"">=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0 XmlObject instance =3D TestSchemaDocument.Factory.= <i>newInstance</i>(</span><b><span style=3D"font-size:10.0pt;font-family:&q= uot;Courier New";color:#7f0055">new</span></b><span style=3D"font-size= :10.0pt;font-family:"Courier New""> XmlOptions());</span><span st= yle=3D"font-size:10.0pt;font-family:"Courier New""><u></u><u></u>= </span></p> <p class=3D"MsoNormal" style=3D"text-autospace:none"><span style=3D"font-si= ze:10.0pt;font-family:"Courier New"">=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0 System.</span><i><span style=3D"font-size:10.0pt;f= ont-family:"Courier New";color:#0000c0">out</span></i><span style= =3D"font-size:10.0pt;font-family:"Courier New"">.println(instance= .schemaType());</span><span style=3D"font-size:10.0pt;font-family:"Cou= rier New""><u></u><u></u></span></p> <p class=3D"MsoNormal" style=3D"text-autospace:none"><span style=3D"font-si= ze:10.0pt;font-family:"Courier New"">=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0 }</span><span style=3D"font-size:10.0pt;font-family:"Courier Ne= w""><u></u><u></u></span></p> <p class=3D"MsoNormal" style=3D"text-autospace:none"><span style=3D"font-si= ze:10.0pt;font-family:"Courier New""><u></u>=A0<u></u></span></p>= <p class=3D"MsoNormal" style=3D"text-autospace:none"><span style=3D"font-si= ze:10.0pt;font-family:"Courier New"">=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0 {</span><span style=3D"font-size:10.0pt;font-family:"Courier Ne= w""><u></u><u></u></span></p> <p class=3D"MsoNormal" style=3D"text-autospace:none"><span style=3D"font-si= ze:10.0pt;font-family:"Courier New"">=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0 SchemaTypeLoader loader =3D XmlBeans.<i>typeLoader= ForClassLoader</i>(SchemaDocument.</span><b><span style=3D"font-size:10.0pt= ;font-family:"Courier New";color:#7f0055">class</span></b><span s= tyle=3D"font-size:10.0pt;font-family:"Courier New"">.getClassLoad= er());</span><span style=3D"font-size:10.0pt;font-family:"Courier New&= quot;"><u></u><u></u></span></p> <p class=3D"MsoNormal" style=3D"text-autospace:none"><span style=3D"font-si= ze:10.0pt;font-family:"Courier New"">=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0 XmlObject instance =3D loader.parse(</span><b><spa= n style=3D"font-size:10.0pt;font-family:"Courier New";color:#7f00= 55">new</span></b><span style=3D"font-size:10.0pt;font-family:"Courier= New""> File(</span><span style=3D"font-size:10.0pt;font-family:"= Courier New";color:#2a00ff">"xsd/testschema.xsd"</span><span= style=3D"font-size:10.0pt;font-family:"Courier New"">),</span><b= ><span style=3D"font-size:10.0pt;font-family:"Courier New";color:= #7f0055">null</span></b><span style=3D"font-size:10.0pt;font-family:"C= ourier New"">, </span><b><span style=3D"font-size:10.0pt;font-family:&= quot;Courier New";color:#7f0055">new</span></b><span style=3D"font-siz= e:10.0pt;font-family:"Courier New""> XmlOptions());</span><span s= tyle=3D"font-size:10.0pt;font-family:"Courier New""><u></u><u></u= ></span></p> <p class=3D"MsoNormal" style=3D"text-autospace:none"><span style=3D"font-si= ze:10.0pt;font-family:"Courier New"">=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0 System.</span><i><span style=3D"font-size:10.0pt;f= ont-family:"Courier New";color:#0000c0">out</span></i><span style= =3D"font-size:10.0pt;font-family:"Courier New"">.println(instance= .schemaType());</span><span style=3D"font-size:10.0pt;font-family:"Cou= rier New""><u></u><u></u></span></p> <p class=3D"MsoNormal" style=3D"text-autospace:none"><span style=3D"font-si= ze:10.0pt;font-family:"Courier New"">=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0 }</span><span style=3D"font-size:10.0pt;font-family:"Courier Ne= w""><u></u><u></u></span></p> <p class=3D"MsoNormal" style=3D"text-autospace:none"><span style=3D"font-si= ze:10.0pt;font-family:"Courier New""><u></u>=A0<u></u></span></p>= <p class=3D"MsoNormal" style=3D"text-autospace:none"><span style=3D"font-si= ze:10.0pt;font-family:"Courier New"">=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0 {</span><span style=3D"font-size:10.0pt;font-family:"Courier Ne= w""><u></u><u></u></span></p> <p class=3D"MsoNormal" style=3D"text-autospace:none"><span style=3D"font-si= ze:10.0pt;font-family:"Courier New"">=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0 XmlObject[] schemaObj =3D </span><b><span style=3D= "font-size:10.0pt;font-family:"Courier New";color:#7f0055">new</s= pan></b><span style=3D"font-size:10.0pt;font-family:"Courier New"= "> XmlObject[]=A0=A0 { XmlObject.Factory.<i>parse</i>(</span><b><span style= =3D"font-size:10.0pt;font-family:"Courier New";color:#7f0055">new= </span></b><span style=3D"font-size:10.0pt;font-family:"Courier New&qu= ot;"> File(</span><span style=3D"font-size:10.0pt;font-family:"Courier= New";color:#2a00ff">"xsd/testschema.xsd"</span><span style= =3D"font-size:10.0pt;font-family:"Courier New"">))};</span><span = style=3D"font-size:10.0pt;font-family:"Courier New""><u></u><u></= u></span></p> <p class=3D"MsoNormal" style=3D"text-autospace:none"><span style=3D"font-si= ze:10.0pt;font-family:"Courier New"">=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0 SchemaTypeSystem schemaTypeObj =3D XmlBeans.<i>com= pileXmlBeans</i>(</span><b><span style=3D"font-size:10.0pt;font-family:&quo= t;Courier New";color:#7f0055">null</span></b><span style=3D"font-size:= 10.0pt;font-family:"Courier New"">, </span><b><span style=3D"font= -size:10.0pt;font-family:"Courier New";color:#7f0055">null</span>= </b><span style=3D"font-size:10.0pt;font-family:"Courier New"">, = schemaObj, </span><b><span style=3D"font-size:10.0pt;font-family:"Cour= ier New";color:#7f0055">null</span></b><span style=3D"font-size:10.0pt= ;font-family:"Courier New"">, </span><b><span style=3D"font-size:= 10.0pt;font-family:"Courier New";color:#7f0055">null</span></b><s= pan style=3D"font-size:10.0pt;font-family:"Courier New"">, </span= ><b><span style=3D"font-size:10.0pt;font-family:"Courier New";col= or:#7f0055">null</span></b><span style=3D"font-size:10.0pt;font-family:&quo= t;Courier New"">, </span><b><span style=3D"font-size:10.0pt;font-famil= y:"Courier New";color:#7f0055">null</span></b><span style=3D"font= -size:10.0pt;font-family:"Courier New"">);</span><span style=3D"f= ont-size:10.0pt;font-family:"Courier New""><u></u><u></u></span><= /p> <p class=3D"MsoNormal" style=3D"text-autospace:none"><span style=3D"font-si= ze:10.0pt;font-family:"Courier New"">=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0 XmlObject instance =3D schemaTypeObj.newInstance(s= chemaTypeObj.documentTypes()[0], </span><b><span style=3D"font-size:10.0pt;= font-family:"Courier New";color:#7f0055">null</span></b><span sty= le=3D"font-size:10.0pt;font-family:"Courier New"">);</span><span = style=3D"font-size:10.0pt;font-family:"Courier New""><u></u><u></= u></span></p> <p class=3D"MsoNormal" style=3D"text-autospace:none"><span style=3D"font-si= ze:10.0pt;font-family:"Courier New"">=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0 System.</span><i><span style=3D"font-size:10.0pt;f= ont-family:"Courier New";color:#0000c0">out</span></i><span style= =3D"font-size:10.0pt;font-family:"Courier New"">.println(instance= .schemaType());</span><span style=3D"font-size:10.0pt;font-family:"Cou= rier New""><u></u><u></u></span></p> <p class=3D"MsoNormal" style=3D"text-autospace:none"><span style=3D"font-si= ze:10.0pt;font-family:"Courier New"">=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0 }</span><span style=3D"font-size:10.0pt;font-family:"Courier Ne= w""><u></u><u></u></span></p> <p class=3D"MsoNormal" style=3D"text-autospace:none"><span style=3D"font-si= ze:10.0pt;font-family:"Courier New""><u></u>=A0<u></u></span></p>= <p class=3D"MsoNormal" style=3D"text-autospace:none"><span style=3D"font-si= ze:10.0pt;font-family:"Courier New"">=A0=A0=A0=A0=A0 }</span><spa= n style=3D"font-size:10.0pt;font-family:"Courier New""><u></u><u>= </u></span></p> <p class=3D"MsoNormal" style=3D"text-autospace:none"><span style=3D"font-si= ze:10.0pt;font-family:"Courier New"">}</span><span style=3D"font-= size:10.0pt;font-family:"Courier New""><u></u><u></u></span></p><= p class=3D"MsoNormal"> <span style=3D"font-size:11.0pt;font-family:"Calibri","sans-= serif";color:#1f497d"><u></u>=A0<u></u></span></p><p class=3D"MsoNorma= l"><span style=3D"font-size:11.0pt;font-family:"Calibri","sa= ns-serif";color:#1f497d"><u></u>=A0<u></u></span></p> <p class=3D"MsoNormal"><b><span style=3D"font-size:10.0pt;font-family:"= ;Tahoma","sans-serif"">From:</span></b><span style=3D"font-s= ize:10.0pt;font-family:"Tahoma","sans-serif""> badger m= ailinglist [mailto:<a href=3D"mailto:[email protected]" target= =3D"_blank">[email protected]</a>] <br> <b>Sent:</b> Monday, January 14, 2013 6:35 AM<br><b>To:</b> <a href=3D"mail= to:[email protected]" target=3D"_blank">[email protected]</a>= <br><b>Subject:</b> Re: Converting from using scomp to SchemaTypeLoader.par= se(...)<u></u><u></u></span></p> <div><div class=3D"h5"><p class=3D"MsoNormal"><u></u>=A0<u></u></p><p class= =3D"MsoNormal" style=3D"margin-bottom:12.0pt">Ok, so I guess no one has eve= r tried this.<br><br>Maybe there's a simpler question:<br><br>If I use = the SchemaTypeLoader.parse method, I struggle to get information about the = schema from that object. I want to iterate through the attributes and eleme= nts declared in the XSD I'm parsing, but all I seem to get is w3 xml sc= hema stuff. Am I trying to do something that isn't supported, or am I j= ust doing it wrong?<br> <br>Any help much appreciated,<br><br>Cheers,<br><br>Badger.<u></u><u></u><= /p><div><p class=3D"MsoNormal">On 8 January 2013 15:42, badger mailinglist = <<a href=3D"mailto:[email protected]" target=3D"_blank">badg= [email protected]</a>> wrote:<u></u><u></u></p> <p class=3D"MsoNormal" style=3D"margin-bottom:12.0pt">Hi,<br><br>Currently,= I take some XSDs (see below for example), generate classes for them (with = scomp -out generatedClasses.jar testschema.xsd), then use those classes in = code with some like:<br> final XmlObject instance =3D TestSchemaDocument.Factory.newInstance(xmlOpti= ons);<br><br>This process now needs to be a bit more dynamic, so I'm tr= ying to use something more like the following:<br><br>final SchemaTypeLoade= r loader =3D XmlBeans.typeLoaderForClassLoader(SchemaDocument.class.getClas= sLoader());<br> XmlOptions xmlOptions =3D new XmlOptions();<br>final XmlObject fileParsedIn= stance =3D loader.parse(new File("C:\\testschema.xsd"), null, new= XmlOptions());<br><br><br>However, I would expect the XmlObject returned i= n both cases to be the same. However, if I recursively iterate through the = properties of these two objects, I get different results i.e. calling insta= nce.schemaType().getProperties() gets different results in each of the case= s.<br> For the instance loaded from the class the getProperties() method returns o= ne element with type 'TestSchema', which itself returns one element= with type 'TestType' and so on as you recur.<br>For the instance l= oaded directly from the xsd file the properties are all things like E=3Dres= triction|D=3Drestriction@<a href=3D"http://www.w3.org/2001/XMLSchema" targe= t=3D"_blank">http://www.w3.org/2001/XMLSchema</a>, which has a property T= =3DlocalSimpleType@<a href=3D"http://www.w3.org/2001/XMLSchema" target=3D"_= blank">http://www.w3.org/2001/XMLSchema</a>, which has a property 'rest= riction' and so on infinitely.<br> <br>I've assumed that these two methods of loading the schema would do = the same thing, but it looks like I'm wrong, can someone point me at th= e method call I need to make to load from the file properly? I'm using = XmlBeans 2.5.0.<br> <br>Thanks!<br><br><br>Example xsd I'm testing this with:<br><br><?x= ml version=3D"1.0" encoding=3D"utf-8"?><br><xs:sc= hema attributeFormDefault=3D"unqualified" elementFormDefault=3D&q= uot;qualified" xmlns:xs=3D"<a href=3D"http://www.w3.org/2001/XMLS= chema" target=3D"_blank">http://www.w3.org/2001/XMLSchema</a>"><br> <br>=A0 <xs:element name=3D"TestSchema" type=3D"TestType&= quot; /><br>=A0 <br>=A0 <xs:complexType name=3D"TestComplexType&= quot;><br>=A0=A0=A0 <xs:sequence><br>=A0=A0=A0=A0=A0 <xs:elemen= t type=3D"xs:string" name=3D"thing" /><br> =A0=A0=A0 </xs:sequence><br>=A0 </xs:complexType><br>=A0 <br>= =A0 <xs:complexType name=3D"TestType"><br>=A0=A0=A0 <xs:= sequence><br>=A0=A0=A0=A0=A0 <xs:element type=3D"TestComplexType= " name=3D"TestComplex"<br> =A0=A0=A0=A0=A0 maxOccurs=3D"unbounded" minOccurs=3D"0"= /><br>=A0=A0=A0 </xs:sequence><br>=A0 </xs:complexType><br>= =A0 <br></xs:schema><u></u><u></u></p></div><p class=3D"MsoNormal"><u= ></u>=A0<u></u></p></div> </div></div></div></blockquote></div><br> --e89a8fb20078a67d6f04d3541da5--