Hi Emiliano, I guess the error messages could be a little better :-) The problem is that when you have a file with imports, the import in the .xsd file typically includes a relative file name for where to find the .xsd file with the imported types in it. To make that work, the loader needs the file location (schemaLocation) for the referencing (main) file. That's why you can't pass null for the second argument of XSDHelper.define() when you are loading a .xsd file with imports.
The other way you tried to do it: XSDHelper.INSTANCE.define(baseXsd, "http://www.example.org/BaseSchema"); didn't work either because you were passing a "schema namespace URI", not the "schema location". If you look at some of the JUnit tests in the sdo impl project you'll see the recommended pattern for calling define. For example, SimpleDynamicTestCase does this: URL url = getClass().getResource(TEST_MODEL); InputStream inputStream = url.openStream(); XSDHelper.INSTANCE.define(inputStream, url.toString()); It passes in the file location that corresponds to the InputStream being loaded. Frank. "emiliano grigis" <[EMAIL PROTECTED]> wrote on 12/21/2006 05:35:15 AM: > Hi, > I have a problem with an xml file based on a schema with a type that is > imported from another schema. I think that the problem it's into the > schemaLocation parameter on the define method. > > > Of course if I use the value null for both the schemaLocation, like: > > XSDHelper.INSTANCE.define(baseXsd, null); > XSDHelper.INSTANCE.define(sampleXsd, null); > > then I receive a > > FeatureNotFoundException: Feature 'baseElement' not found. (http:///temp.xml, > 4, 18) > > exception when loading the xml document. > > > If I specify the schemaLocation option like this: > > XSDHelper.INSTANCE.define(baseXsd, " > http://www.example.org/BaseSchema"); > XSDHelper.INSTANCE.define(sampleXsd, null); > > then I have a > > java.lang.IllegalArgumentException: > org.apache.tuscany.sdo.util.resource.SDOXMLResourceImpl > > without further explanations. > > > Many thanks in advance > Emiliano > > > The Java code: > > //base.xsd > //Schema with only a type definition > InputStream baseXsd = Thread.currentThread() > .getContextClassLoader().getResourceAsStream( > "base.xsd"); > > //sample.xsd > //Schema that import the type definition from the other xsd > InputStream sampleXsd = Thread.currentThread() > .getContextClassLoader().getResourceAsStream( > "sample.xsd"); > > //sample.xml > //document conform to the sample.xsd > InputStream sampleXml = Thread.currentThread() > .getContextClassLoader().getResourceAsStream( > "sample.xml"); > > //Load the Schemas > XSDHelper.INSTANCE.define(baseXsd, " > http://www.example.org/BaseSchema"); > XSDHelper.INSTANCE.define(sampleXsd, null); > System.out.println("-------------->>> Schemas read"); > > //Load xml > XMLDocument xDoc = XMLHelper.INSTANCE.load(sampleXml); > System.out.println("-------------->>> Xml read"); > > > The base.xsd source: > > <?xml version="1.0" encoding="UTF-8"?> > <schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace=" > http://www.example.org/BaseSchema" xmlns:base=" > http://www.example.org/BaseSchema" > > <complexType name="baseType"> > <sequence> > <element name="baseElement" type="string" minOccurs="1" > maxOccurs="1"/> > </sequence> > </complexType> > </schema> > > > The sample.xsd source: > > <?xml version="1.0" encoding="UTF-8"?> > <schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace=" > http://www.example.org/SampleSchema" xmlns:sample=" > http://www.example.org/SampleSchema" xmlns:base=" > http://www.example.org/BaseSchema"> > <import namespace="http://www.example.org/BaseSchema" schemaLocation=" > base.xsd"/> > <complexType name="sampleType"> > <sequence> > <element name="sampleElement" type="base:baseType"></element> > </sequence> > </complexType> > <element name="myElement" type="sample:sampleType"></element> > </schema> > > > The sample.xml source: > > <?xml version="1.0" encoding="UTF-8"?> > <sample:myElement xmlns:base="http://www.example.org/BaseSchema" > xmlns:sample="http://www.example.org/SampleSchema" xmlns:xsi=" > http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" > http://www.example.org/SampleSchema sample.xsd > http://www.example.org/BaseSchema base.xsd "> > <sampleElement> > <baseElement>this is my content</baseElement> > </sampleElement> > </sample:myElement> --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
