Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » XML Schema Definition (XSD) » HowTo reference definitions in multiple schemas
HowTo reference definitions in multiple schemas [message #52699] Thu, 09 September 2004 21:25 Go to next message
Tim Almdal is currently offline Tim AlmdalFriend
Messages: 12
Registered: July 2009
Junior Member
I'm trying to parse a the schema's contained in a WSDL file. Everything
works fine when the <wsdl:types> has only one schema defined. I'm working
with wsdl files that have more than 1 schema defined in the <wsdl:types>
element.

For example, I have the following two schemas (see below) defined in the
wsdl. TestSchema1 defines a base type and TestSchema2 tries to extend the
definition.

I've tried the following code and have not be able to get the base
definition to resolve as the XSDParticle definition keeps on showing up as
null. I've tries a variation of this code and seem to be stumped. I
can't seem to find anything in the newsgroup. Have I really missed the
boat and misunderstood?

Any help or direction would be greatly appreciated :-)

Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put( "xsd",
new XSDResourceFactoryImpl());
_resourceSet = new ResourceSetImpl();
XSDSchema xsdSchema1 = XSDSchemaImpl.createSchema(rschemaRootElement1);
Resource rs1 =
_resourceSet.createResource(URI.createURI(root.getLocalName( )+ ".xsd"));
rs.getContents().add(xsdSchema1);
XSDSchema xsdSchema2 = XSDSchemaImpl.createSchema(rschemaRootElement2);
Resource rs2 =
_resourceSet.createResource(URI.createURI(root.getLocalName( )+ ".xsd"));
rs.getContents().add(xsdSchema2);


<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://Exception.www.ibm.com">

<xsd:complexType name="SomethingWrong">
<xsd:annotation>
<xsd:documentation>The base type for all bc online web services
exceptions</xsd:documentation>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="LocalizedMessage" type="xsd:string"/>
<xsd:element name="Message" type="xsd:string"/>
<xsd:element name="StackTrace" type="xsd:string"/>
<xsd:element name="return-code" type="xsd:int"/>
</xsd:sequence>
</xsd:complexType>

</xsd:schema>

and

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.ibm.com"
xmlns:excp="http://Exception.www.ibm.com"
xmlns:impl="http://www.ibm.com">
<xsd:element name="GlobalSimpleType" type="xsd:string"></xsd:element>

<xsd:complexType name="WrongThing1">
<xsd:annotation>
<xsd:documentation>Contains Logoff error information</xsd:documentation>
</xsd:annotation>
<xsd:complexContent>
<xsd:extension base="excp:SomethingWrong" />
</xsd:complexContent>
</xsd:complexType>

<xsd:complexType name="WrongThing2">
<xsd:complexContent>
<xsd:extension base="excp:SomethingWrong">
<xsd:sequence>
<xsd:element name="format-error" type="xsd:int"/>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>

</xsd:schema>
Re: HowTo reference definitions in multiple schemas [message #52726 is a reply to message #52699] Fri, 10 September 2004 15:02 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

Tim,

You don't seem to have any import statements. You need an import for
each namespace that you reference. Did you know that an XSDResourceImpl
can directly handle a .wsdl file? You just need to register a factory
for "wsdl" the same way as for "xsd". It will find all the schema nodes
and create XSDSchemas for them (and will resolve any cross schema imports).


Tim wrote:

>I'm trying to parse a the schema's contained in a WSDL file. Everything
>works fine when the <wsdl:types> has only one schema defined. I'm working
>with wsdl files that have more than 1 schema defined in the <wsdl:types>
>element.
>
>For example, I have the following two schemas (see below) defined in the
>wsdl. TestSchema1 defines a base type and TestSchema2 tries to extend the
>definition.
>
>I've tried the following code and have not be able to get the base
>definition to resolve as the XSDParticle definition keeps on showing up as
>null. I've tries a variation of this code and seem to be stumped. I
>can't seem to find anything in the newsgroup. Have I really missed the
>boat and misunderstood?
>
>Any help or direction would be greatly appreciated :-)
>
> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put( "xsd",
>new XSDResourceFactoryImpl());
>_resourceSet = new ResourceSetImpl();
>XSDSchema xsdSchema1 = XSDSchemaImpl.createSchema(rschemaRootElement1);
>Resource rs1 =
> _resourceSet.createResource(URI.createURI(root.getLocalName( )+ ".xsd"));
> rs.getContents().add(xsdSchema1);
>XSDSchema xsdSchema2 = XSDSchemaImpl.createSchema(rschemaRootElement2);
>Resource rs2 =
> _resourceSet.createResource(URI.createURI(root.getLocalName( )+ ".xsd"));
> rs.getContents().add(xsdSchema2);
>
>
><xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> targetNamespace="http://Exception.www.ibm.com">
>
> <xsd:complexType name="SomethingWrong">
> <xsd:annotation>
> <xsd:documentation>The base type for all bc online web services
>exceptions</xsd:documentation>
> </xsd:annotation>
> <xsd:sequence>
> <xsd:element name="LocalizedMessage" type="xsd:string"/>
> <xsd:element name="Message" type="xsd:string"/>
> <xsd:element name="StackTrace" type="xsd:string"/>
> <xsd:element name="return-code" type="xsd:int"/>
> </xsd:sequence>
> </xsd:complexType>
>
></xsd:schema>
>
>and
>
><?xml version="1.0" encoding="UTF-8"?>
><xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> targetNamespace="http://www.ibm.com"
> xmlns:excp="http://Exception.www.ibm.com"
> xmlns:impl="http://www.ibm.com">
> <xsd:element name="GlobalSimpleType" type="xsd:string"></xsd:element>
>
> <xsd:complexType name="WrongThing1">
> <xsd:annotation>
> <xsd:documentation>Contains Logoff error information</xsd:documentation>
> </xsd:annotation>
> <xsd:complexContent>
> <xsd:extension base="excp:SomethingWrong" />
> </xsd:complexContent>
> </xsd:complexType>
>
> <xsd:complexType name="WrongThing2">
> <xsd:complexContent>
> <xsd:extension base="excp:SomethingWrong">
> <xsd:sequence>
> <xsd:element name="format-error" type="xsd:int"/>
> </xsd:sequence>
> </xsd:extension>
> </xsd:complexContent>
> </xsd:complexType>
>
></xsd:schema>
>
>
>
Re: HowTo reference definitions in multiple schemas [message #52753 is a reply to message #52726] Fri, 10 September 2004 16:37 Go to previous messageGo to next message
Tim Almdal is currently offline Tim AlmdalFriend
Messages: 12
Registered: July 2009
Junior Member
Thanks Ed.

I just tried it this morning by adding an import to the second schema. And
it still didn't find the reference to the first schema. I have also tried
using the validate method hoping that would resolve the references

Until about fifteen minutes ago, I didn't know that I could parse a WSDL
directly. If I was only interested in the schemas contained in the WSDL I
could be happy with that solution. But I also want to use the rest of the
content of the WSDL file to create a generic test tool for testing our web
services. I was using WSDL4J to parse the WSDL file, from which I have
access to the root Element of each schema definition. So I would like to
avoid parsing the file twice.

What I thought I could do was then create one resource set and then add
each schema to it in the order it was defined in the WSDL. I guess the
part I'm missing is how to name the first schema (via its uri) so that the
second schema will resolve references to the first schema in the same
resourceSet.

Again, thanks for any insights you may have.

Ed Merks wrote:

> Tim,

> You don't seem to have any import statements. You need an import for
> each namespace that you reference. Did you know that an XSDResourceImpl
> can directly handle a .wsdl file? You just need to register a factory
> for "wsdl" the same way as for "xsd". It will find all the schema nodes
> and create XSDSchemas for them (and will resolve any cross schema imports).


> Tim wrote:

> >I'm trying to parse a the schema's contained in a WSDL file. Everything
> >works fine when the <wsdl:types> has only one schema defined. I'm working
> >with wsdl files that have more than 1 schema defined in the <wsdl:types>
> >element.
> >
> >For example, I have the following two schemas (see below) defined in the
> >wsdl. TestSchema1 defines a base type and TestSchema2 tries to extend the
> >definition.
> >
> >I've tried the following code and have not be able to get the base
> >definition to resolve as the XSDParticle definition keeps on showing up as
> >null. I've tries a variation of this code and seem to be stumped. I
> >can't seem to find anything in the newsgroup. Have I really missed the
> >boat and misunderstood?
> >
> >Any help or direction would be greatly appreciated :-)
> >
> > Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put( "xsd",
> >new XSDResourceFactoryImpl());
> >_resourceSet = new ResourceSetImpl();
> >XSDSchema xsdSchema1 = XSDSchemaImpl.createSchema(rschemaRootElement1);
> >Resource rs1 =
> > _resourceSet.createResource(URI.createURI(root.getLocalName( )+ ".xsd"));
> > rs.getContents().add(xsdSchema1);
> >XSDSchema xsdSchema2 = XSDSchemaImpl.createSchema(rschemaRootElement2);
> >Resource rs2 =
> > _resourceSet.createResource(URI.createURI(root.getLocalName( )+ ".xsd"));
> > rs.getContents().add(xsdSchema2);
> >
> >
> ><xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> > targetNamespace="http://Exception.www.ibm.com">
> >
> > <xsd:complexType name="SomethingWrong">
> > <xsd:annotation>
> > <xsd:documentation>The base type for all bc online web services
> >exceptions</xsd:documentation>
> > </xsd:annotation>
> > <xsd:sequence>
> > <xsd:element name="LocalizedMessage" type="xsd:string"/>
> > <xsd:element name="Message" type="xsd:string"/>
> > <xsd:element name="StackTrace" type="xsd:string"/>
> > <xsd:element name="return-code" type="xsd:int"/>
> > </xsd:sequence>
> > </xsd:complexType>
> >
> ></xsd:schema>
> >
> >and
> >
> ><?xml version="1.0" encoding="UTF-8"?>
> ><xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> > targetNamespace="http://www.ibm.com"
> > xmlns:excp="http://Exception.www.ibm.com"
> > xmlns:impl="http://www.ibm.com">
> > <xsd:element name="GlobalSimpleType" type="xsd:string"></xsd:element>
> >
> > <xsd:complexType name="WrongThing1">
> > <xsd:annotation>
> > <xsd:documentation>Contains Logoff error information</xsd:documentation>
> > </xsd:annotation>
> > <xsd:complexContent>
> > <xsd:extension base="excp:SomethingWrong" />
> > </xsd:complexContent>
> > </xsd:complexType>
> >
> > <xsd:complexType name="WrongThing2">
> > <xsd:complexContent>
> > <xsd:extension base="excp:SomethingWrong">
> > <xsd:sequence>
> > <xsd:element name="format-error" type="xsd:int"/>
> > </xsd:sequence>
> > </xsd:extension>
> > </xsd:complexContent>
> > </xsd:complexType>
> >
> ></xsd:schema>
> >
> >
> >
Re:Figured it out :-) [message #52780 is a reply to message #52753] Fri, 10 September 2004 19:12 Go to previous message
Tim Almdal is currently offline Tim AlmdalFriend
Messages: 12
Registered: July 2009
Junior Member
I figured out what I needed to do. After the resource has been created
and the schema content has been loaded, I set the resource URI to the
target namespace of the schema I just loaded. This seems to allow the
next schema to find the first definition and resolve definitions from it.

The code sort of looks like this:
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put( "xsd",
new XSDResourceFactoryImpl());
ResourceSet = _resourceSet = new ResourceSetImpl();
XSDSchema xsdSchema1 = XSDSchemaImpl.createSchema(rschemaRootElement1);
Resource rs1 = _resourceSet.createResource(URI.createURI("*.xsd"));
rs1.getContents().add(xsdSchema1);
rs1.setURI(URI.createURI(xsdSchema1.getTargetNamespace());
xsdSchema1.validate();

XSDSchema xsdSchema2 = XSDSchemaImpl.createSchema(rschemaRootElement2);
Resource rs2 = _resourceSet.createResource(URI.createURI("*.xsd"));
rs2.getContents().add(xsdSchema2);
rs2.setURI(URI.createURI(xsdSchema2.getTargetNamespace());
xsdSchema2.validate();

Tim wrote:

> Thanks Ed.

> I just tried it this morning by adding an import to the second schema. And
> it still didn't find the reference to the first schema. I have also tried
> using the validate method hoping that would resolve the references

> Until about fifteen minutes ago, I didn't know that I could parse a WSDL
> directly. If I was only interested in the schemas contained in the WSDL I
> could be happy with that solution. But I also want to use the rest of the
> content of the WSDL file to create a generic test tool for testing our web
> services. I was using WSDL4J to parse the WSDL file, from which I have
> access to the root Element of each schema definition. So I would like to
> avoid parsing the file twice.

> What I thought I could do was then create one resource set and then add
> each schema to it in the order it was defined in the WSDL. I guess the
> part I'm missing is how to name the first schema (via its uri) so that the
> second schema will resolve references to the first schema in the same
> resourceSet.

> Again, thanks for any insights you may have.

> Ed Merks wrote:

> > Tim,

> > You don't seem to have any import statements. You need an import for
> > each namespace that you reference. Did you know that an XSDResourceImpl
> > can directly handle a .wsdl file? You just need to register a factory
> > for "wsdl" the same way as for "xsd". It will find all the schema nodes
> > and create XSDSchemas for them (and will resolve any cross schema imports).


> > Tim wrote:

> > >I'm trying to parse a the schema's contained in a WSDL file. Everything
> > >works fine when the <wsdl:types> has only one schema defined. I'm working
> > >with wsdl files that have more than 1 schema defined in the <wsdl:types>
> > >element.
> > >
> > >For example, I have the following two schemas (see below) defined in the
> > >wsdl. TestSchema1 defines a base type and TestSchema2 tries to extend the
> > >definition.
> > >
> > >I've tried the following code and have not be able to get the base
> > >definition to resolve as the XSDParticle definition keeps on showing up as
> > >null. I've tries a variation of this code and seem to be stumped. I
> > >can't seem to find anything in the newsgroup. Have I really missed the
> > >boat and misunderstood?
> > >
> > >Any help or direction would be greatly appreciated :-)
> > >
> > > Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put( "xsd",
> > >new XSDResourceFactoryImpl());
> > >_resourceSet = new ResourceSetImpl();
> > >XSDSchema xsdSchema1 = XSDSchemaImpl.createSchema(rschemaRootElement1);
> > >Resource rs1 =
> > > _resourceSet.createResource(URI.createURI(root.getLocalName( )+ ".xsd"));
> > > rs.getContents().add(xsdSchema1);
> > >XSDSchema xsdSchema2 = XSDSchemaImpl.createSchema(rschemaRootElement2);
> > >Resource rs2 =
> > > _resourceSet.createResource(URI.createURI(root.getLocalName( )+ ".xsd"));
> > > rs.getContents().add(xsdSchema2);
> > >
> > >
> > ><xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> > > targetNamespace="http://Exception.www.ibm.com">
> > >
> > > <xsd:complexType name="SomethingWrong">
> > > <xsd:annotation>
> > > <xsd:documentation>The base type for all bc online web services
> > >exceptions</xsd:documentation>
> > > </xsd:annotation>
> > > <xsd:sequence>
> > > <xsd:element name="LocalizedMessage" type="xsd:string"/>
> > > <xsd:element name="Message" type="xsd:string"/>
> > > <xsd:element name="StackTrace" type="xsd:string"/>
> > > <xsd:element name="return-code" type="xsd:int"/>
> > > </xsd:sequence>
> > > </xsd:complexType>
> > >
> > ></xsd:schema>
> > >
> > >and
> > >
> > ><?xml version="1.0" encoding="UTF-8"?>
> > ><xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> > > targetNamespace="http://www.ibm.com"
> > > xmlns:excp="http://Exception.www.ibm.com"
> > > xmlns:impl="http://www.ibm.com">
> > > <xsd:element name="GlobalSimpleType" type="xsd:string"></xsd:element>
> > >
> > > <xsd:complexType name="WrongThing1">
> > > <xsd:annotation>
> > > <xsd:documentation>Contains Logoff error
information</xsd:documentation>
> > > </xsd:annotation>
> > > <xsd:complexContent>
> > > <xsd:extension base="excp:SomethingWrong" />
> > > </xsd:complexContent>
> > > </xsd:complexType>
> > >
> > > <xsd:complexType name="WrongThing2">
> > > <xsd:complexContent>
> > > <xsd:extension base="excp:SomethingWrong">
> > > <xsd:sequence>
> > > <xsd:element name="format-error" type="xsd:int"/>
> > > </xsd:sequence>
> > > </xsd:extension>
> > > </xsd:complexContent>
> > > </xsd:complexType>
> > >
> > ></xsd:schema>
> > >
> > >
> > >
Re: HowTo reference definitions in multiple schemas [message #591507 is a reply to message #52699] Fri, 10 September 2004 15:02 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Tim,

You don't seem to have any import statements. You need an import for
each namespace that you reference. Did you know that an XSDResourceImpl
can directly handle a .wsdl file? You just need to register a factory
for "wsdl" the same way as for "xsd". It will find all the schema nodes
and create XSDSchemas for them (and will resolve any cross schema imports).


Tim wrote:

>I'm trying to parse a the schema's contained in a WSDL file. Everything
>works fine when the <wsdl:types> has only one schema defined. I'm working
>with wsdl files that have more than 1 schema defined in the <wsdl:types>
>element.
>
>For example, I have the following two schemas (see below) defined in the
>wsdl. TestSchema1 defines a base type and TestSchema2 tries to extend the
>definition.
>
>I've tried the following code and have not be able to get the base
>definition to resolve as the XSDParticle definition keeps on showing up as
>null. I've tries a variation of this code and seem to be stumped. I
>can't seem to find anything in the newsgroup. Have I really missed the
>boat and misunderstood?
>
>Any help or direction would be greatly appreciated :-)
>
> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put( "xsd",
>new XSDResourceFactoryImpl());
>_resourceSet = new ResourceSetImpl();
>XSDSchema xsdSchema1 = XSDSchemaImpl.createSchema(rschemaRootElement1);
>Resource rs1 =
> _resourceSet.createResource(URI.createURI(root.getLocalName( )+ ".xsd"));
> rs.getContents().add(xsdSchema1);
>XSDSchema xsdSchema2 = XSDSchemaImpl.createSchema(rschemaRootElement2);
>Resource rs2 =
> _resourceSet.createResource(URI.createURI(root.getLocalName( )+ ".xsd"));
> rs.getContents().add(xsdSchema2);
>
>
><xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> targetNamespace="http://Exception.www.ibm.com">
>
> <xsd:complexType name="SomethingWrong">
> <xsd:annotation>
> <xsd:documentation>The base type for all bc online web services
>exceptions</xsd:documentation>
> </xsd:annotation>
> <xsd:sequence>
> <xsd:element name="LocalizedMessage" type="xsd:string"/>
> <xsd:element name="Message" type="xsd:string"/>
> <xsd:element name="StackTrace" type="xsd:string"/>
> <xsd:element name="return-code" type="xsd:int"/>
> </xsd:sequence>
> </xsd:complexType>
>
></xsd:schema>
>
>and
>
><?xml version="1.0" encoding="UTF-8"?>
><xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> targetNamespace="http://www.ibm.com"
> xmlns:excp="http://Exception.www.ibm.com"
> xmlns:impl="http://www.ibm.com">
> <xsd:element name="GlobalSimpleType" type="xsd:string"></xsd:element>
>
> <xsd:complexType name="WrongThing1">
> <xsd:annotation>
> <xsd:documentation>Contains Logoff error information</xsd:documentation>
> </xsd:annotation>
> <xsd:complexContent>
> <xsd:extension base="excp:SomethingWrong" />
> </xsd:complexContent>
> </xsd:complexType>
>
> <xsd:complexType name="WrongThing2">
> <xsd:complexContent>
> <xsd:extension base="excp:SomethingWrong">
> <xsd:sequence>
> <xsd:element name="format-error" type="xsd:int"/>
> </xsd:sequence>
> </xsd:extension>
> </xsd:complexContent>
> </xsd:complexType>
>
></xsd:schema>
>
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: HowTo reference definitions in multiple schemas [message #591515 is a reply to message #52726] Fri, 10 September 2004 16:37 Go to previous message
Tim Almdal is currently offline Tim AlmdalFriend
Messages: 12
Registered: July 2009
Junior Member
Thanks Ed.

I just tried it this morning by adding an import to the second schema. And
it still didn't find the reference to the first schema. I have also tried
using the validate method hoping that would resolve the references

Until about fifteen minutes ago, I didn't know that I could parse a WSDL
directly. If I was only interested in the schemas contained in the WSDL I
could be happy with that solution. But I also want to use the rest of the
content of the WSDL file to create a generic test tool for testing our web
services. I was using WSDL4J to parse the WSDL file, from which I have
access to the root Element of each schema definition. So I would like to
avoid parsing the file twice.

What I thought I could do was then create one resource set and then add
each schema to it in the order it was defined in the WSDL. I guess the
part I'm missing is how to name the first schema (via its uri) so that the
second schema will resolve references to the first schema in the same
resourceSet.

Again, thanks for any insights you may have.

Ed Merks wrote:

> Tim,

> You don't seem to have any import statements. You need an import for
> each namespace that you reference. Did you know that an XSDResourceImpl
> can directly handle a .wsdl file? You just need to register a factory
> for "wsdl" the same way as for "xsd". It will find all the schema nodes
> and create XSDSchemas for them (and will resolve any cross schema imports).


> Tim wrote:

> >I'm trying to parse a the schema's contained in a WSDL file. Everything
> >works fine when the <wsdl:types> has only one schema defined. I'm working
> >with wsdl files that have more than 1 schema defined in the <wsdl:types>
> >element.
> >
> >For example, I have the following two schemas (see below) defined in the
> >wsdl. TestSchema1 defines a base type and TestSchema2 tries to extend the
> >definition.
> >
> >I've tried the following code and have not be able to get the base
> >definition to resolve as the XSDParticle definition keeps on showing up as
> >null. I've tries a variation of this code and seem to be stumped. I
> >can't seem to find anything in the newsgroup. Have I really missed the
> >boat and misunderstood?
> >
> >Any help or direction would be greatly appreciated :-)
> >
> > Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put( "xsd",
> >new XSDResourceFactoryImpl());
> >_resourceSet = new ResourceSetImpl();
> >XSDSchema xsdSchema1 = XSDSchemaImpl.createSchema(rschemaRootElement1);
> >Resource rs1 =
> > _resourceSet.createResource(URI.createURI(root.getLocalName( )+ ".xsd"));
> > rs.getContents().add(xsdSchema1);
> >XSDSchema xsdSchema2 = XSDSchemaImpl.createSchema(rschemaRootElement2);
> >Resource rs2 =
> > _resourceSet.createResource(URI.createURI(root.getLocalName( )+ ".xsd"));
> > rs.getContents().add(xsdSchema2);
> >
> >
> ><xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> > targetNamespace="http://Exception.www.ibm.com">
> >
> > <xsd:complexType name="SomethingWrong">
> > <xsd:annotation>
> > <xsd:documentation>The base type for all bc online web services
> >exceptions</xsd:documentation>
> > </xsd:annotation>
> > <xsd:sequence>
> > <xsd:element name="LocalizedMessage" type="xsd:string"/>
> > <xsd:element name="Message" type="xsd:string"/>
> > <xsd:element name="StackTrace" type="xsd:string"/>
> > <xsd:element name="return-code" type="xsd:int"/>
> > </xsd:sequence>
> > </xsd:complexType>
> >
> ></xsd:schema>
> >
> >and
> >
> ><?xml version="1.0" encoding="UTF-8"?>
> ><xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> > targetNamespace="http://www.ibm.com"
> > xmlns:excp="http://Exception.www.ibm.com"
> > xmlns:impl="http://www.ibm.com">
> > <xsd:element name="GlobalSimpleType" type="xsd:string"></xsd:element>
> >
> > <xsd:complexType name="WrongThing1">
> > <xsd:annotation>
> > <xsd:documentation>Contains Logoff error information</xsd:documentation>
> > </xsd:annotation>
> > <xsd:complexContent>
> > <xsd:extension base="excp:SomethingWrong" />
> > </xsd:complexContent>
> > </xsd:complexType>
> >
> > <xsd:complexType name="WrongThing2">
> > <xsd:complexContent>
> > <xsd:extension base="excp:SomethingWrong">
> > <xsd:sequence>
> > <xsd:element name="format-error" type="xsd:int"/>
> > </xsd:sequence>
> > </xsd:extension>
> > </xsd:complexContent>
> > </xsd:complexType>
> >
> ></xsd:schema>
> >
> >
> >
Re:Figured it out :-) [message #591523 is a reply to message #52753] Fri, 10 September 2004 19:12 Go to previous message
Tim Almdal is currently offline Tim AlmdalFriend
Messages: 12
Registered: July 2009
Junior Member
I figured out what I needed to do. After the resource has been created
and the schema content has been loaded, I set the resource URI to the
target namespace of the schema I just loaded. This seems to allow the
next schema to find the first definition and resolve definitions from it.

The code sort of looks like this:
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put( "xsd",
new XSDResourceFactoryImpl());
ResourceSet = _resourceSet = new ResourceSetImpl();
XSDSchema xsdSchema1 = XSDSchemaImpl.createSchema(rschemaRootElement1);
Resource rs1 = _resourceSet.createResource(URI.createURI("*.xsd"));
rs1.getContents().add(xsdSchema1);
rs1.setURI(URI.createURI(xsdSchema1.getTargetNamespace());
xsdSchema1.validate();

XSDSchema xsdSchema2 = XSDSchemaImpl.createSchema(rschemaRootElement2);
Resource rs2 = _resourceSet.createResource(URI.createURI("*.xsd"));
rs2.getContents().add(xsdSchema2);
rs2.setURI(URI.createURI(xsdSchema2.getTargetNamespace());
xsdSchema2.validate();

Tim wrote:

> Thanks Ed.

> I just tried it this morning by adding an import to the second schema. And
> it still didn't find the reference to the first schema. I have also tried
> using the validate method hoping that would resolve the references

> Until about fifteen minutes ago, I didn't know that I could parse a WSDL
> directly. If I was only interested in the schemas contained in the WSDL I
> could be happy with that solution. But I also want to use the rest of the
> content of the WSDL file to create a generic test tool for testing our web
> services. I was using WSDL4J to parse the WSDL file, from which I have
> access to the root Element of each schema definition. So I would like to
> avoid parsing the file twice.

> What I thought I could do was then create one resource set and then add
> each schema to it in the order it was defined in the WSDL. I guess the
> part I'm missing is how to name the first schema (via its uri) so that the
> second schema will resolve references to the first schema in the same
> resourceSet.

> Again, thanks for any insights you may have.

> Ed Merks wrote:

> > Tim,

> > You don't seem to have any import statements. You need an import for
> > each namespace that you reference. Did you know that an XSDResourceImpl
> > can directly handle a .wsdl file? You just need to register a factory
> > for "wsdl" the same way as for "xsd". It will find all the schema nodes
> > and create XSDSchemas for them (and will resolve any cross schema imports).


> > Tim wrote:

> > >I'm trying to parse a the schema's contained in a WSDL file. Everything
> > >works fine when the <wsdl:types> has only one schema defined. I'm working
> > >with wsdl files that have more than 1 schema defined in the <wsdl:types>
> > >element.
> > >
> > >For example, I have the following two schemas (see below) defined in the
> > >wsdl. TestSchema1 defines a base type and TestSchema2 tries to extend the
> > >definition.
> > >
> > >I've tried the following code and have not be able to get the base
> > >definition to resolve as the XSDParticle definition keeps on showing up as
> > >null. I've tries a variation of this code and seem to be stumped. I
> > >can't seem to find anything in the newsgroup. Have I really missed the
> > >boat and misunderstood?
> > >
> > >Any help or direction would be greatly appreciated :-)
> > >
> > > Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put( "xsd",
> > >new XSDResourceFactoryImpl());
> > >_resourceSet = new ResourceSetImpl();
> > >XSDSchema xsdSchema1 = XSDSchemaImpl.createSchema(rschemaRootElement1);
> > >Resource rs1 =
> > > _resourceSet.createResource(URI.createURI(root.getLocalName( )+ ".xsd"));
> > > rs.getContents().add(xsdSchema1);
> > >XSDSchema xsdSchema2 = XSDSchemaImpl.createSchema(rschemaRootElement2);
> > >Resource rs2 =
> > > _resourceSet.createResource(URI.createURI(root.getLocalName( )+ ".xsd"));
> > > rs.getContents().add(xsdSchema2);
> > >
> > >
> > ><xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> > > targetNamespace="http://Exception.www.ibm.com">
> > >
> > > <xsd:complexType name="SomethingWrong">
> > > <xsd:annotation>
> > > <xsd:documentation>The base type for all bc online web services
> > >exceptions</xsd:documentation>
> > > </xsd:annotation>
> > > <xsd:sequence>
> > > <xsd:element name="LocalizedMessage" type="xsd:string"/>
> > > <xsd:element name="Message" type="xsd:string"/>
> > > <xsd:element name="StackTrace" type="xsd:string"/>
> > > <xsd:element name="return-code" type="xsd:int"/>
> > > </xsd:sequence>
> > > </xsd:complexType>
> > >
> > ></xsd:schema>
> > >
> > >and
> > >
> > ><?xml version="1.0" encoding="UTF-8"?>
> > ><xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> > > targetNamespace="http://www.ibm.com"
> > > xmlns:excp="http://Exception.www.ibm.com"
> > > xmlns:impl="http://www.ibm.com">
> > > <xsd:element name="GlobalSimpleType" type="xsd:string"></xsd:element>
> > >
> > > <xsd:complexType name="WrongThing1">
> > > <xsd:annotation>
> > > <xsd:documentation>Contains Logoff error
information</xsd:documentation>
> > > </xsd:annotation>
> > > <xsd:complexContent>
> > > <xsd:extension base="excp:SomethingWrong" />
> > > </xsd:complexContent>
> > > </xsd:complexType>
> > >
> > > <xsd:complexType name="WrongThing2">
> > > <xsd:complexContent>
> > > <xsd:extension base="excp:SomethingWrong">
> > > <xsd:sequence>
> > > <xsd:element name="format-error" type="xsd:int"/>
> > > </xsd:sequence>
> > > </xsd:extension>
> > > </xsd:complexContent>
> > > </xsd:complexType>
> > >
> > ></xsd:schema>
> > >
> > >
> > >
Previous Topic:HowTo reference definitions in multiple schemas
Next Topic:Adding XSD components to an existing schema
Goto Forum:
  


Current Time: Fri Mar 29 07:27:58 GMT 2024

Powered by FUDForum. Page generated in 0.03818 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top