Re: Converting from using scomp to SchemaTypeLoader.parse(...)

badger mailinglist <[email protected]> Mon, 14 Jan 2013 11:35:08 +0000
Newsgroups gmane.text.xml.xmlbeans.user
Message-ID <CAF7=Xdg0n2D-zFkq63W9xaLs7gF27dkucLaixQmBk3N1caohHg@mail.gmail.com>
--f46d04478ad386da7904d33e0925
Content-Type: text/plain; charset=ISO-8859-1

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 attributes
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]>wrote:

> Hi,
>
> 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:
> final XmlObject instance =
> 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 =
> XmlBeans.typeLoaderForClassLoader(SchemaDocument.class.getClassLoader());
> XmlOptions xmlOptions = new XmlOptions();
> final XmlObject fileParsedInstance = 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 two
> objects, I get different results i.e. calling
> instance.schemaType().getProperties() gets different results in each of the
> 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=restriction|D=restriction@http://www.w3.org/2001/XMLSchema,
> which has a property T=localSimpleType@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 method
> 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="1.0" encoding="utf-8"?>
> <xs:schema attributeFormDefault="unqualified"
> elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema
> ">
>
>   <xs:element name="TestSchema" type="TestType" />
>
>   <xs:complexType name="TestComplexType">
>     <xs:sequence>
>       <xs:element type="xs:string" name="thing" />
>     </xs:sequence>
>   </xs:complexType>
>
>   <xs:complexType name="TestType">
>     <xs:sequence>
>       <xs:element type="TestComplexType" name="TestComplex"
>       maxOccurs="unbounded" minOccurs="0" />
>     </xs:sequence>
>   </xs:complexType>
>
> </xs:schema>
>
>

--f46d04478ad386da7904d33e0925
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Ok, so I guess no one has ever tried this.<br><br>Maybe there&#39;s a simpl=
er 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 thr=
ough the attributes and elements declared in the XSD I&#39;m parsing, but a=
ll I seem to get is w3 xml schema stuff. Am I trying to do something that i=
sn&#39;t supported, or am I just doing it wrong?<br>
<br>Any help much appreciated,<br><br>Cheers,<br><br>Badger.<br><br><div cl=
ass=3D"gmail_quote">On 8 January 2013 15:42, badger mailinglist <span dir=
=3D"ltr">&lt;<a href=3D"mailto:[email protected]" target=3D"_bl=
ank">[email protected]</a>&gt;</span> wrote:<br>
<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex">Hi,<br><br>Currently, I take some XSDs (see =
below for example), generate classes for them (with scomp -out generatedCla=
sses.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&#39;m trying to u=
se something more like the following:<br><br>final SchemaTypeLoader loader =
=3D XmlBeans.typeLoaderForClassLoader(SchemaDocument.class.getClassLoader()=
);<br>

XmlOptions xmlOptions =3D new XmlOptions();<br>final XmlObject fileParsedIn=
stance =3D loader.parse(new File(&quot;C:\\testschema.xsd&quot;), 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 &#39;TestSchema&#39;, which itself returns one element=
 with type &#39;TestType&#39; 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 &#39;rest=
riction&#39; and so on infinitely.<br>

<br>I&#39;ve assumed that these two methods of loading the schema would do =
the same thing, but it looks like I&#39;m wrong, can someone point me at th=
e method call I need to make to load from the file properly? I&#39;m using =
XmlBeans 2.5.0.<br>

<br>Thanks!<br><br><br>Example xsd I&#39;m testing this with:<br><br>&lt;?x=
ml version=3D&quot;1.0&quot; encoding=3D&quot;utf-8&quot;?&gt;<br>&lt;xs:sc=
hema attributeFormDefault=3D&quot;unqualified&quot; elementFormDefault=3D&q=
uot;qualified&quot; xmlns:xs=3D&quot;<a href=3D"http://www.w3.org/2001/XMLS=
chema" target=3D"_blank">http://www.w3.org/2001/XMLSchema</a>&quot;&gt;<br>

<br>=A0 &lt;xs:element name=3D&quot;TestSchema&quot; type=3D&quot;TestType&=
quot; /&gt;<br>=A0 <br>=A0 &lt;xs:complexType name=3D&quot;TestComplexType&=
quot;&gt;<br>=A0=A0=A0 &lt;xs:sequence&gt;<br>=A0=A0=A0=A0=A0 &lt;xs:elemen=
t type=3D&quot;xs:string&quot; name=3D&quot;thing&quot; /&gt;<br>

=A0=A0=A0 &lt;/xs:sequence&gt;<br>=A0 &lt;/xs:complexType&gt;<br>=A0 <br>=
=A0 &lt;xs:complexType name=3D&quot;TestType&quot;&gt;<br>=A0=A0=A0 &lt;xs:=
sequence&gt;<br>=A0=A0=A0=A0=A0 &lt;xs:element type=3D&quot;TestComplexType=
&quot; name=3D&quot;TestComplex&quot;<br>

=A0=A0=A0=A0=A0 maxOccurs=3D&quot;unbounded&quot; minOccurs=3D&quot;0&quot;=
 /&gt;<br>=A0=A0=A0 &lt;/xs:sequence&gt;<br>=A0 &lt;/xs:complexType&gt;<br>=
=A0 <br>&lt;/xs:schema&gt;<br><br>
</blockquote></div><br>

--f46d04478ad386da7904d33e0925--