Hi Radu,
 
Thank you for your help. I made it work using the following code:
 
  private SchemaTypeSystem generateSchemaTypeSystem(URL xsd) {
    System.out.println("Using URL");
    XmlObject[] schema = new XmlObject[1];
    XmlOptions po = new XmlOptions();
    po.setCompileDownloadUrls();
    try {
      schema[0] = XmlObject.Factory.parse(xsd, po);
    } catch (XmlException e) {
      System.out.println("[Validation:generateSchemaTypeSystem] XmlException: " 
+ e.getCause());
      e.printStackTrace();
      return null;
    }
    catch (IOException e) {
      System.out.println("[Validation:generateSchemaTypeSystem] IOException: " 
+ e.getCause());
      e.printStackTrace();
      return null;
    }
    return generateSchemaTypeSystem(schema);
  }
 
private SchemaTypeSystem generateSchemaTypeSystem(XmlObject[] schema) {
    SchemaTypeSystem sts;
    Collection compErrors = new ArrayList();
    XmlOptions schemaOptions = new XmlOptions();
    schemaOptions.setCompileDownloadUrls();
    schemaOptions.setErrorListener(compErrors);
    try {
      sts = XmlBeans.compileXsd(schema, XmlBeans.getBuiltinTypeSystem(), 
schemaOptions);
    } catch (XmlException e) {
      if (compErrors.isEmpty()) {
        System.out.println("[Validation:generateSchemaTypeSystem] XmlException: 
" + e.getCause());
        e.printStackTrace();
      }
      System.out.println("[Validation:generateSchemaTypeSystem] XmlException: " 
+ e.getCause() + " Schema invalid");
      e.printStackTrace();
      for (Iterator i = compErrors.iterator(); i.hasNext();) {
        System.out.println("[Validation:generateSchemaTypeSystem] XSD Error: " 
+ i.next());
      }
      return null;
    }
    return sts;
  }
 
Tine Damkjær Jørgensen
Consultant
 
Netcompany - IT and business consulting
Grønningen 19
DK-1270 København K
Denmark
Mobile: +45 2228 2958
Phone: +45 7013 1440
Fax: +45 7013 1450
www.netcompany.com

________________________________

Fra: Radu Preotiuc-Pietro [mailto:[EMAIL PROTECTED]
Sendt: fr 17-02-2006 00:51
Til: [email protected]
Emne: RE: Problems generating SchemaTypeSystem from xsds with include and/or 
import elements using URL


Your code looks fine. Can you share the value of the URL that you pass in? Do 
you run on Windows or Unix? Finally, have you tried doing (new 
File(...)).getURL() and see if that works?
 
Radu

________________________________

From: Tine Damkjær Jørgensen [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, February 07, 2006 7:29 AM
To: [email protected]
Subject: Problems generating SchemaTypeSystem from xsds with include and/or 
import elements using URL


Hi,
 
I'm trying to parse an xsd containing import elements with schemalocations 
given as relative paths. The parsing is done using an URL as argument. When 
generating the SchemaTypeSystem I get the following errors:
 
* error: Could not load resource "test4.xsd" (network downloads disabled).
* error: src-resolve: element '[EMAIL PROTECTED]/namespace2' not found.
 
Doing the same thing using File instead of URL works just fine.
 
My code looks as follows:
 
  private SchemaTypeSystem generateSchemaTypeSystem(URL xsd) {
    XmlObject[] schema = new XmlObject[1];
    XmlOptions po = new XmlOptions();
    po.setCompileDownloadUrls();
    try {
      schema[0] = XmlObject.Factory.parse(xsd, po);
    } catch (XmlException e) {
      System.out.println("[Validation:generateSchemaTypeSystem] XmlException: " 
+ e.getCause());
      e.printStackTrace();
      return null;
    }
    catch (IOException e) {
      System.out.println("[Validation:generateSchemaTypeSystem] IOException: " 
+ e.getCause());
      e.printStackTrace();
      return null;
    }

    return generateSchemaTypeSystem(schema);
  }
 
 private SchemaTypeSystem generateSchemaTypeSystem(XmlObject[] schema) {
    SchemaTypeSystem sts;
    Collection compErrors = new ArrayList();
    XmlOptions schemaOptions = new XmlOptions();
    //schemaOptions.setCompileDownloadUrls();
    schemaOptions.setErrorListener(compErrors);
    for(int i = 0; i < schema.length; i++) {
      System.out.println("Schema no. " + i);
      if(schema[i] == null) System.out.println("Schema no. " + i + " null");
    }
    try {
      sts = XmlBeans.compileXsd(schema, XmlBeans.getBuiltinTypeSystem(), 
schemaOptions);
    } catch (XmlException e) {
      if (compErrors.isEmpty()) {
        System.out.println("[Validation:generateSchemaTypeSystem] XmlException: 
" + e.getCause());
        e.printStackTrace();
      }
      System.out.println("[Validation:generateSchemaTypeSystem] XmlException: " 
+ e.getCause() + " Schema invalid");
      e.printStackTrace();
      for (Iterator i = compErrors.iterator(); i.hasNext();) {
        System.out.println("[Validation:generateSchemaTypeSystem] XSD Error: " 
+ i.next());
      }
      return null;
    }
    return sts;
  }
 
And my xsds looks like this:
 
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema 
<http://www.w3.org/2001/XMLSchema> " xmlns="test/namespace1"  
xmlns:pre4="test/namespace2" targetNamespace="test/namespace1" 
elementFormDefault="qualified">
<xs:import namespace="test/namespace2" schemaLocation="test4.xsd"/>
 <xs:element name="test3">
  <xs:complexType>
   <xs:sequence>
    <xs:element name="elem1" type="xs:string"/>
    <xs:element ref="pre4:test4"/>
   </xs:sequence>
  </xs:complexType>
 </xs:element>
</xs:schema>
 
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema 
<http://www.w3.org/2001/XMLSchema> " xmlns="test/namespace2" 
targetNamespace="test/namespace2" elementFormDefault="qualified">
 <xs:element name="test4" type="type4"/>
 <xs:simpleType name="type4">
  <xs:restriction base="xs:string"/>
 </xs:simpleType>
</xs:schema>
 
Does anyone know how I can solve my problem?
 
Thanks in advance,
 
Tine
 
 

<<winmail.dat>>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to