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

"Paul Gillen" <[email protected]> Mon, 14 Jan 2013 18:27:45 -0500
Newsgroups gmane.text.xml.xmlbeans.user
Message-ID <[email protected]>
------=_NextPart_000_01E4_01CDF284.DA0F40D0
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: 7bit

Boy, I wish I got paid for this crap.

 

Full answer here:
http://www.oracle.com/technetwork/articles/entarch/incremental-compilation-x
mlbeans-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's 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=TestSchema

D=schema@http://www.w3.org/2001/XMLSchema

D=TestSchema

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 = new TestSchema();

            ts.go(args);

      }

 

      private void go(String[] args) throws Exception {

            {

                  XmlObject instance =
TestSchemaDocument.Factory.newInstance(new XmlOptions());

                  System.out.println(instance.schemaType());

            }

 

            {

                  SchemaTypeLoader loader =
XmlBeans.typeLoaderForClassLoader(SchemaDocument.class.getClassLoader());

                  XmlObject instance = loader.parse(new
File("xsd/testschema.xsd"),null, new XmlOptions());

                  System.out.println(instance.schemaType());

            }

 

            {

                  XmlObject[] schemaObj = new XmlObject[]   {
XmlObject.Factory.parse(new File("xsd/testschema.xsd"))};

                  SchemaTypeSystem schemaTypeObj =
XmlBeans.compileXmlBeans(null, null, schemaObj, null, null, null, null);

                  XmlObject instance =
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 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>

 


------=_NextPart_000_01E4_01CDF284.DA0F40D0
Content-Type: text/html;
	charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

<html xmlns:v=3D"urn:schemas-microsoft-com:vml" =
xmlns:o=3D"urn:schemas-microsoft-com:office:office" =
xmlns:w=3D"urn:schemas-microsoft-com:office:word" =
xmlns:m=3D"http://schemas.microsoft.com/office/2004/12/omml" =
xmlns=3D"http://www.w3.org/TR/REC-html40"><head><meta =
http-equiv=3DContent-Type content=3D"text/html; =
charset=3Dus-ascii"><meta name=3DGenerator content=3D"Microsoft Word 14 =
(filtered medium)"><style><!--
/* Font Definitions */
@font-face
	{font-family:Calibri;
	panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
	{font-family:Tahoma;
	panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
	{margin:0in;
	margin-bottom:.0001pt;
	font-size:12.0pt;
	font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
	{mso-style-priority:99;
	color:blue;
	text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
	{mso-style-priority:99;
	color:purple;
	text-decoration:underline;}
span.EmailStyle17
	{mso-style-type:personal-reply;
	font-family:"Calibri","sans-serif";
	color:#1F497D;}
.MsoChpDefault
	{mso-style-type:export-only;
	font-family:"Calibri","sans-serif";}
@page WordSection1
	{size:8.5in 11.0in;
	margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
	{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext=3D"edit" spidmax=3D"1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext=3D"edit">
<o:idmap v:ext=3D"edit" data=3D"1" />
</o:shapelayout></xml><![endif]--></head><body lang=3DEN-US link=3Dblue =
vlink=3Dpurple><div class=3DWordSection1><p class=3DMsoNormal><span =
style=3D'font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497=
D'>Boy, I wish I got paid for this crap.<o:p></o:p></span></p><p =
class=3DMsoNormal><span =
style=3D'font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497=
D'><o:p>&nbsp;</o:p></span></p><p class=3DMsoNormal><span =
style=3D'font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497=
D'>Full answer here: <a =
href=3D"http://www.oracle.com/technetwork/articles/entarch/incremental-co=
mpilation-xmlbeans-089127.html">http://www.oracle.com/technetwork/article=
s/entarch/incremental-compilation-xmlbeans-089127.html</a><o:p></o:p></sp=
an></p><p class=3DMsoNormal><span =
style=3D'font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497=
D'><o:p>&nbsp;</o:p></span></p><p class=3DMsoNormal><span =
style=3D'font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497=
D'>In your first example you had compiled your schema and created an =
object to describe parsed XML.<o:p></o:p></span></p><p =
class=3DMsoNormal><span =
style=3D'font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497=
D'><o:p>&nbsp;</o:p></span></p><p class=3DMsoNormal><span =
style=3D'font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497=
D'>In you second example you parsed the XSD, which is after all XML, =
and, surprise, it&#8217;s described by W3C XSD.<o:p></o:p></span></p><p =
class=3DMsoNormal><span =
style=3D'font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497=
D'><o:p>&nbsp;</o:p></span></p><p class=3DMsoNormal><span =
style=3D'font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497=
D'>What you want to do, and I would be interested in hearing why, is to =
compile the XSD on the fly.<o:p></o:p></span></p><p =
class=3DMsoNormal><span =
style=3D'font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497=
D'><o:p>&nbsp;</o:p></span></p><p class=3DMsoNormal><span =
style=3D'font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497=
D'>The output of the example below is:<o:p></o:p></span></p><p =
class=3DMsoNormal style=3D'margin-left:.5in;text-autospace:none'><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New";color:black'>D=3DTestSchema</span><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New"'><o:p></o:p></span></p><p class=3DMsoNormal =
style=3D'margin-left:.5in;text-autospace:none'><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New";color:black'>D=3Dschema@http://www.w3.org/2001/XMLSchema</span><span=
 style=3D'font-size:10.0pt;font-family:"Courier =
New"'><o:p></o:p></span></p><p class=3DMsoNormal =
style=3D'margin-left:.5in'><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New";color:black'>D=3DTestSchema<o:p></o:p></span></p><p =
class=3DMsoNormal><span =
style=3D'font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497=
D'>where the first is your first example, the second is your second =
example, and the third is from compiling the XSD on the =
fly.<o:p></o:p></span></p><p class=3DMsoNormal><span =
style=3D'font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497=
D'><o:p>&nbsp;</o:p></span></p><p class=3DMsoNormal><span =
style=3D'font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497=
D'>Hope this helps.<o:p></o:p></span></p><p class=3DMsoNormal><span =
style=3D'font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497=
D'><o:p>&nbsp;</o:p></span></p><p class=3DMsoNormal><span =
style=3D'font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497=
D'>Cheers,<o:p></o:p></span></p><p class=3DMsoNormal><span =
style=3D'font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497=
D'>Paul<o:p></o:p></span></p><p class=3DMsoNormal><span =
style=3D'font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497=
D'><o:p>&nbsp;</o:p></span></p><p class=3DMsoNormal =
style=3D'text-autospace:none'><b><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New";color:#7F0055'>package</span></b><span =
style=3D'font-size:10.0pt;font-family:"Courier New";color:black'> =
com.riveralph;</span><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New"'><o:p></o:p></span></p><p class=3DMsoNormal =
style=3D'text-autospace:none'><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New"'><o:p>&nbsp;</o:p></span></p><p class=3DMsoNormal =
style=3D'text-autospace:none'><b><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New";color:#7F0055'>import</span></b><span =
style=3D'font-size:10.0pt;font-family:"Courier New";color:black'> =
java.io.File;</span><span style=3D'font-size:10.0pt;font-family:"Courier =
New"'><o:p></o:p></span></p><p class=3DMsoNormal =
style=3D'text-autospace:none'><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New"'><o:p>&nbsp;</o:p></span></p><p class=3DMsoNormal =
style=3D'text-autospace:none'><b><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New";color:#7F0055'>import</span></b><span =
style=3D'font-size:10.0pt;font-family:"Courier New";color:black'> =
noNamespace.TestSchemaDocument;</span><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New"'><o:p></o:p></span></p><p class=3DMsoNormal =
style=3D'text-autospace:none'><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New"'><o:p>&nbsp;</o:p></span></p><p class=3DMsoNormal =
style=3D'text-autospace:none'><b><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New";color:#7F0055'>import</span></b><span =
style=3D'font-size:10.0pt;font-family:"Courier New";color:black'> =
org.apache.xmlbeans.SchemaTypeLoader;</span><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New"'><o:p></o:p></span></p><p class=3DMsoNormal =
style=3D'text-autospace:none'><b><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New";color:#7F0055'>import</span></b><span =
style=3D'font-size:10.0pt;font-family:"Courier New";color:black'> =
org.apache.xmlbeans.SchemaTypeSystem;</span><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New"'><o:p></o:p></span></p><p class=3DMsoNormal =
style=3D'text-autospace:none'><b><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New";color:#7F0055'>import</span></b><span =
style=3D'font-size:10.0pt;font-family:"Courier New";color:black'> =
org.apache.xmlbeans.XmlBeans;</span><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New"'><o:p></o:p></span></p><p class=3DMsoNormal =
style=3D'text-autospace:none'><b><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New";color:#7F0055'>import</span></b><span =
style=3D'font-size:10.0pt;font-family:"Courier New";color:black'> =
org.apache.xmlbeans.XmlObject;</span><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New"'><o:p></o:p></span></p><p class=3DMsoNormal =
style=3D'text-autospace:none'><b><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New";color:#7F0055'>import</span></b><span =
style=3D'font-size:10.0pt;font-family:"Courier New";color:black'> =
org.apache.xmlbeans.XmlOptions;</span><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New"'><o:p></o:p></span></p><p class=3DMsoNormal =
style=3D'text-autospace:none'><b><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New";color:#7F0055'>import</span></b><span =
style=3D'font-size:10.0pt;font-family:"Courier New";color:black'> =
org.apache.xmlbeans.impl.xb.xsdschema.SchemaDocument;</span><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New"'><o:p></o:p></span></p><p class=3DMsoNormal =
style=3D'text-autospace:none'><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New"'><o:p>&nbsp;</o:p></span></p><p class=3DMsoNormal =
style=3D'text-autospace:none'><b><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New";color:#7F0055'>public</span></b><span =
style=3D'font-size:10.0pt;font-family:"Courier New";color:black'> =
</span><b><span style=3D'font-size:10.0pt;font-family:"Courier =
New";color:#7F0055'>class</span></b><span =
style=3D'font-size:10.0pt;font-family:"Courier New";color:black'> =
TestSchema {</span><span style=3D'font-size:10.0pt;font-family:"Courier =
New"'><o:p></o:p></span></p><p class=3DMsoNormal =
style=3D'text-autospace:none'><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New";color:black'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><b><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New";color:#7F0055'>public</span></b><span =
style=3D'font-size:10.0pt;font-family:"Courier New";color:black'> =
</span><b><span style=3D'font-size:10.0pt;font-family:"Courier =
New";color:#7F0055'>static</span></b><span =
style=3D'font-size:10.0pt;font-family:"Courier New";color:black'> =
</span><b><span style=3D'font-size:10.0pt;font-family:"Courier =
New";color:#7F0055'>void</span></b><span =
style=3D'font-size:10.0pt;font-family:"Courier New";color:black'> =
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";color:black'> =
Exception {</span><span style=3D'font-size:10.0pt;font-family:"Courier =
New"'><o:p></o:p></span></p><p class=3DMsoNormal =
style=3D'text-autospace:none'><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New";color:black'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 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-size:10.0pt;font-family:"Courier New";color:black'> =
TestSchema();</span><span style=3D'font-size:10.0pt;font-family:"Courier =
New"'><o:p></o:p></span></p><p class=3DMsoNormal =
style=3D'text-autospace:none'><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New";color:black'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp; ts.go(args);</span><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New"'><o:p></o:p></span></p><p class=3DMsoNormal =
style=3D'text-autospace:none'><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New";color:black'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New"'><o:p></o:p></span></p><p class=3DMsoNormal =
style=3D'text-autospace:none'><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New"'><o:p>&nbsp;</o:p></span></p><p class=3DMsoNormal =
style=3D'text-autospace:none'><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New";color:black'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><b><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New";color:#7F0055'>private</span></b><span =
style=3D'font-size:10.0pt;font-family:"Courier New";color:black'> =
</span><b><span style=3D'font-size:10.0pt;font-family:"Courier =
New";color:#7F0055'>void</span></b><span =
style=3D'font-size:10.0pt;font-family:"Courier New";color:black'> =
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";color:black'> =
Exception {</span><span style=3D'font-size:10.0pt;font-family:"Courier =
New"'><o:p></o:p></span></p><p class=3DMsoNormal =
style=3D'text-autospace:none'><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New";color:black'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp; {</span><span style=3D'font-size:10.0pt;font-family:"Courier =
New"'><o:p></o:p></span></p><p class=3DMsoNormal =
style=3D'text-autospace:none'><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New";color:black'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; XmlObject instance =3D =
TestSchemaDocument.Factory.<i>newInstance</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";color:black'> =
XmlOptions());</span><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New"'><o:p></o:p></span></p><p class=3DMsoNormal =
style=3D'text-autospace:none'><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New";color:black'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.</span><i><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New";color:#0000C0'>out</span></i><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New";color:black'>.println(instance.schemaType());</span><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New"'><o:p></o:p></span></p><p class=3DMsoNormal =
style=3D'text-autospace:none'><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New";color:black'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp; }</span><span style=3D'font-size:10.0pt;font-family:"Courier =
New"'><o:p></o:p></span></p><p class=3DMsoNormal =
style=3D'text-autospace:none'><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New"'><o:p>&nbsp;</o:p></span></p><p class=3DMsoNormal =
style=3D'text-autospace:none'><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New";color:black'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp; {</span><span style=3D'font-size:10.0pt;font-family:"Courier =
New"'><o:p></o:p></span></p><p class=3DMsoNormal =
style=3D'text-autospace:none'><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New";color:black'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SchemaTypeLoader loader =
=3D =
XmlBeans.<i>typeLoaderForClassLoader</i>(SchemaDocument.</span><b><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New";color:#7F0055'>class</span></b><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New";color:black'>.getClassLoader());</span><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New"'><o:p></o:p></span></p><p class=3DMsoNormal =
style=3D'text-autospace:none'><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New";color:black'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; XmlObject instance =3D =
loader.parse(</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";color:black'> =
File(</span><span style=3D'font-size:10.0pt;font-family:"Courier =
New";color:#2A00FF'>&quot;xsd/testschema.xsd&quot;</span><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New";color:black'>),</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";color:black'>, =
</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";color:black'> =
XmlOptions());</span><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New"'><o:p></o:p></span></p><p class=3DMsoNormal =
style=3D'text-autospace:none'><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New";color:black'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.</span><i><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New";color:#0000C0'>out</span></i><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New";color:black'>.println(instance.schemaType());</span><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New"'><o:p></o:p></span></p><p class=3DMsoNormal =
style=3D'text-autospace:none'><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New";color:black'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp; }</span><span style=3D'font-size:10.0pt;font-family:"Courier =
New"'><o:p></o:p></span></p><p class=3DMsoNormal =
style=3D'text-autospace:none'><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New"'><o:p>&nbsp;</o:p></span></p><p class=3DMsoNormal =
style=3D'text-autospace:none'><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New";color:black'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp; {</span><span style=3D'font-size:10.0pt;font-family:"Courier =
New"'><o:p></o:p></span></p><p class=3DMsoNormal =
style=3D'text-autospace:none'><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New";color:black'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; XmlObject[] schemaObj =
=3D </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";color:black'> =
XmlObject[]&nbsp;&nbsp; { 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";color:black'> =
File(</span><span style=3D'font-size:10.0pt;font-family:"Courier =
New";color:#2A00FF'>&quot;xsd/testschema.xsd&quot;</span><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New";color:black'>))};</span><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New"'><o:p></o:p></span></p><p class=3DMsoNormal =
style=3D'text-autospace:none'><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New";color:black'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SchemaTypeSystem =
schemaTypeObj =3D XmlBeans.<i>compileXmlBeans</i>(</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";color:black'>, =
</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";color:black'>, =
schemaObj, </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";color:black'>, =
</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";color:black'>, =
</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";color:black'>, =
</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";color:black'>);</span><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New"'><o:p></o:p></span></p><p class=3DMsoNormal =
style=3D'text-autospace:none'><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New";color:black'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; XmlObject instance =3D =
schemaTypeObj.newInstance(schemaTypeObj.documentTypes()[0], =
</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";color:black'>);</span><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New"'><o:p></o:p></span></p><p class=3DMsoNormal =
style=3D'text-autospace:none'><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New";color:black'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.</span><i><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New";color:#0000C0'>out</span></i><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New";color:black'>.println(instance.schemaType());</span><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New"'><o:p></o:p></span></p><p class=3DMsoNormal =
style=3D'text-autospace:none'><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New";color:black'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp; }</span><span style=3D'font-size:10.0pt;font-family:"Courier =
New"'><o:p></o:p></span></p><p class=3DMsoNormal =
style=3D'text-autospace:none'><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New"'><o:p>&nbsp;</o:p></span></p><p class=3DMsoNormal =
style=3D'text-autospace:none'><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New";color:black'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New"'><o:p></o:p></span></p><p class=3DMsoNormal =
style=3D'text-autospace:none'><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New";color:black'>}</span><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New"'><o:p></o:p></span></p><p class=3DMsoNormal><span =
style=3D'font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497=
D'><o:p>&nbsp;</o:p></span></p><p class=3DMsoNormal><span =
style=3D'font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497=
D'><o:p>&nbsp;</o:p></span></p><p class=3DMsoNormal><b><span =
style=3D'font-size:10.0pt;font-family:"Tahoma","sans-serif"'>From:</span>=
</b><span style=3D'font-size:10.0pt;font-family:"Tahoma","sans-serif"'> =
badger mailinglist [mailto:[email protected]] =
<br><b>Sent:</b> Monday, January 14, 2013 6:35 AM<br><b>To:</b> =
[email protected]<br><b>Subject:</b> Re: Converting from using =
scomp to SchemaTypeLoader.parse(...)<o:p></o:p></span></p><p =
class=3DMsoNormal><o:p>&nbsp;</o:p></p><p class=3DMsoNormal =
style=3D'margin-bottom:12.0pt'>Ok, so I guess no one has ever 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 =
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?<br><br>Any help much =
appreciated,<br><br>Cheers,<br><br>Badger.<o:p></o:p></p><div><p =
class=3DMsoNormal>On 8 January 2013 15:42, badger mailinglist &lt;<a =
href=3D"mailto:[email protected]" =
target=3D"_blank">[email protected]</a>&gt; =
wrote:<o:p></o:p></p><p class=3DMsoNormal =
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(xmlOptions);<br><br>This process =
now needs to be a bit more dynamic, so I'm trying to use 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 =
fileParsedInstance =3D loader.parse(new =
File(&quot;C:\\testschema.xsd&quot;), null, new =
XmlOptions());<br><br><br>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.<br>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.<br>For the instance loaded directly from the xsd file the =
properties are all things like E=3Drestriction|D=3Drestriction@<a =
href=3D"http://www.w3.org/2001/XMLSchema" =
target=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 'restriction' 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 the 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>&lt;?xml version=3D&quot;1.0&quot; =
encoding=3D&quot;utf-8&quot;?&gt;<br>&lt;xs:schema =
attributeFormDefault=3D&quot;unqualified&quot; =
elementFormDefault=3D&quot;qualified&quot; xmlns:xs=3D&quot;<a =
href=3D"http://www.w3.org/2001/XMLSchema" =
target=3D"_blank">http://www.w3.org/2001/XMLSchema</a>&quot;&gt;<br><br>&=
nbsp; &lt;xs:element name=3D&quot;TestSchema&quot; =
type=3D&quot;TestType&quot; /&gt;<br>&nbsp; <br>&nbsp; =
&lt;xs:complexType =
name=3D&quot;TestComplexType&quot;&gt;<br>&nbsp;&nbsp;&nbsp; =
&lt;xs:sequence&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;xs:element =
type=3D&quot;xs:string&quot; name=3D&quot;thing&quot; =
/&gt;<br>&nbsp;&nbsp;&nbsp; &lt;/xs:sequence&gt;<br>&nbsp; =
&lt;/xs:complexType&gt;<br>&nbsp; <br>&nbsp; &lt;xs:complexType =
name=3D&quot;TestType&quot;&gt;<br>&nbsp;&nbsp;&nbsp; =
&lt;xs:sequence&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;xs:element =
type=3D&quot;TestComplexType&quot; =
name=3D&quot;TestComplex&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
maxOccurs=3D&quot;unbounded&quot; minOccurs=3D&quot;0&quot; =
/&gt;<br>&nbsp;&nbsp;&nbsp; &lt;/xs:sequence&gt;<br>&nbsp; =
&lt;/xs:complexType&gt;<br>&nbsp; =
<br>&lt;/xs:schema&gt;<o:p></o:p></p></div><p =
class=3DMsoNormal><o:p>&nbsp;</o:p></p></div></body></html>
------=_NextPart_000_01E4_01CDF284.DA0F40D0--