You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@tuscany.apache.org by Claus Straube <cl...@xdoo.de> on 2008/08/11 15:28:29 UTC

Generating a DataObject from XML with XML Schema types

Hello,

I've got a XML Schema and a XML instance of this schema. Now I want to 
generate a DataObject from the given XML instance. This works fine, but not 
as expected. If I've got a schema like this:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
targetNamespace="http://www.organisation_01.com/xmlschema/v1.0/Person" 
xmlns:tns="http://www.organisation_01.com/xmlschema/v1.0/Person" 
elementFormDefault="qualified">
	<xs:element name="person" type="personType"/>
	
	<xs:complexType name="personType">
		<xs:all>
			<xs:element name="firstname" type="xs:string"/>
			<xs:element name="secondname" type="xs:string"/>
		</xs:all>
	</xs:complexType>
	
</xs:schema>

And my XML instance looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<tns:person
	xmlns:tns="http://www.organisation_01.com/xmlschema/v1.0/Person" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://www.organisation_01.com/xmlschema/v1.0/Person 
http://localhost:8080/xmlschema/organisation_01/person.xsd">
	<tns:firstname>Peter</tns:firstname>
	<tns:secondname>Pan</tns:secondname>
</tns:person>

I can read in the XMl instance with (scope is my HelperContext):

		InputStream in = SdoDroolsTest.class.getResourceAsStream("/person01.xml");
		XMLDocument xml = scope.getXMLHelper().load(in);
		DataObject sdo_root = xml.getRootObject();

But the rootObject is not from type "personType" as expected. This is a big 
problem for me, because I've to do a rule based type mapping - this is quite 
difficult with generic types. My questions:

1. is there the possibility to declare sdo_root as "personType"...
2. or better - can Tuscany do this for me while generating the SDO from my 
XML? 

Thank's in advance for your help!

Claus

Re: Generating a DataObject from XML with XML Schema types

Posted by Claus Straube <cl...@xdoo.de>.
Hello Frank,

works perfect. That's exactly what I wanted. I think there is no need to do 
the registration automatically, if it works this way.

You saved my day ;) Thank you.

Best regards - Claus

Am Montag, 11. August 2008 16:03:46 schrieb Frank Budinsky:
> Hi Claus,
>
> Tuscany doesn't automatically load metadata (schemas) on the fly. You need
> to register the types before you load the instances. You need to execute
> something like this before calling XMLHelper.load():
>
>   URL url = SdoDroolsTest.class.getResource("/person.xsd");
>   getScope().getXSDHelper().define(url.openStream(), url.toString());
>
> Automatically registering types, based on schemaLocation attributes in the
> XML, is something we've talked about adding as a load option, but nobody
> has found the time to look into implementing it.
>
> Frank.
>
> Claus Straube <cl...@xdoo.de> wrote on 08/11/2008 09:28:29 AM:
> > Hello,
> >
> > I've got a XML Schema and a XML instance of this schema. Now I want to
> > generate a DataObject from the given XML instance. This works fine, but
>
> not
>
> > as expected. If I've got a schema like this:
> >
> > <?xml version="1.0" encoding="UTF-8"?>
> > <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
> > targetNamespace="http://www.organisation_01.com/xmlschema/v1.0/Person"
> > xmlns:tns="http://www.organisation_01.com/xmlschema/v1.0/Person"
> > elementFormDefault="qualified">
> >    <xs:element name="person" type="personType"/>
> >
> >    <xs:complexType name="personType">
> >       <xs:all>
> >          <xs:element name="firstname" type="xs:string"/>
> >          <xs:element name="secondname" type="xs:string"/>
> >       </xs:all>
> >    </xs:complexType>
> >
> > </xs:schema>
> >
> > And my XML instance looks like this:
> >
> > <?xml version="1.0" encoding="UTF-8"?>
> > <tns:person
> >    xmlns:tns="http://www.organisation_01.com/xmlschema/v1.0/Person"
> > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> > xsi:schemaLocation="http://www.organisation_01.com/xmlschema/v1.0/Person
> >
> > http://localhost:8080/xmlschema/organisation_01/person.xsd">
> >    <tns:firstname>Peter</tns:firstname>
> >    <tns:secondname>Pan</tns:secondname>
> > </tns:person>
> >
> > I can read in the XMl instance with (scope is my HelperContext):
> >
> >       InputStream in = SdoDroolsTest.class.
> > getResourceAsStream("/person01.xml");
> >       XMLDocument xml = scope.getXMLHelper().load(in);
> >       DataObject sdo_root = xml.getRootObject();
> >
> > But the rootObject is not from type "personType" as expected. This is a
>
> big
>
> > problem for me, because I've to do a rule based type mapping - this is
>
> quite
>
> > difficult with generic types. My questions:
> >
> > 1. is there the possibility to declare sdo_root as "personType"...
> > 2. or better - can Tuscany do this for me while generating the SDO from
>
> my
>
> > XML?
> >
> > Thank's in advance for your help!
> >
> > Claus



-- 
Claus Straube

Schleißheimer Str. 215
80809 München
Tel. 089 - 1430 1172

Re: Generating a DataObject from XML with XML Schema types

Posted by Frank Budinsky <fr...@ca.ibm.com>.
Hi Claus,

Tuscany doesn't automatically load metadata (schemas) on the fly. You need 
to register the types before you load the instances. You need to execute 
something like this before calling XMLHelper.load():

  URL url = SdoDroolsTest.class.getResource("/person.xsd");
  getScope().getXSDHelper().define(url.openStream(), url.toString());

Automatically registering types, based on schemaLocation attributes in the 
XML, is something we've talked about adding as a load option, but nobody 
has found the time to look into implementing it.

Frank.

Claus Straube <cl...@xdoo.de> wrote on 08/11/2008 09:28:29 AM:

> Hello,
> 
> I've got a XML Schema and a XML instance of this schema. Now I want to 
> generate a DataObject from the given XML instance. This works fine, but 
not 
> as expected. If I've got a schema like this:
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
> targetNamespace="http://www.organisation_01.com/xmlschema/v1.0/Person" 
> xmlns:tns="http://www.organisation_01.com/xmlschema/v1.0/Person" 
> elementFormDefault="qualified">
>    <xs:element name="person" type="personType"/>
> 
>    <xs:complexType name="personType">
>       <xs:all>
>          <xs:element name="firstname" type="xs:string"/>
>          <xs:element name="secondname" type="xs:string"/>
>       </xs:all>
>    </xs:complexType>
> 
> </xs:schema>
> 
> And my XML instance looks like this:
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <tns:person
>    xmlns:tns="http://www.organisation_01.com/xmlschema/v1.0/Person" 
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
> xsi:schemaLocation="http://www.organisation_01.com/xmlschema/v1.0/Person 

> http://localhost:8080/xmlschema/organisation_01/person.xsd">
>    <tns:firstname>Peter</tns:firstname>
>    <tns:secondname>Pan</tns:secondname>
> </tns:person>
> 
> I can read in the XMl instance with (scope is my HelperContext):
> 
>       InputStream in = SdoDroolsTest.class.
> getResourceAsStream("/person01.xml");
>       XMLDocument xml = scope.getXMLHelper().load(in);
>       DataObject sdo_root = xml.getRootObject();
> 
> But the rootObject is not from type "personType" as expected. This is a 
big 
> problem for me, because I've to do a rule based type mapping - this is 
quite 
> difficult with generic types. My questions:
> 
> 1. is there the possibility to declare sdo_root as "personType"...
> 2. or better - can Tuscany do this for me while generating the SDO from 
my 
> XML? 
> 
> Thank's in advance for your help!
> 
> Claus