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 <[EMAIL PROTECTED]> 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