> Are all necessary prefixes declared in both schemas? 

  Yes. I have continued to try and here is what I have found:

  - validation works if one the schemas is referenced through
schemaLocation in the document. The reference is absolute and really
refer to the schema file. In all other cases thing does not work.

  This is not what I want; I simply want that schemaLocation attribute
is not considered, if any value exist. The reason: during runtime, I
would discover where the schema is located (somewhere in my classpath)
and then I want to provide this information during validation to the
parser. Therefore, I could move my application quite easy anywhere and
not to change anything.

  Here is the code snippet:

String SCHEMA_LANGUAGE =
      "http://java.sun.com/xml/jaxp/properties/schemaLanguage";,
        XML_SCHEMA =
      "http://www.w3.org/2001/XMLSchema";,
        SCHEMA_SOURCE =
      "http://java.sun.com/xml/jaxp/properties/schemaSource";;
        try {
        DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
        factory.setNamespaceAware(true);
        factory.setValidating(true);
        factory.setNamespaceAware(true);
        factory.setValidating(true);
        try
        {
         factory.setAttribute(SCHEMA_LANGUAGE,XML_SCHEMA);

factory.setAttribute(SCHEMA_SOURCE,ClassLoader.getSystemResourceAsStream("de/fhg/ipsi/oasys/mgn/spec/test2.xsd"));
}
          catch(IllegalArgumentException x)
          {
             System.err.println("Your DOM parser is not JAXP 1.2
compliant.");
          }
        DocumentBuilder builder = factory.newDocumentBuilder();
        builder.setErrorHandler(new ErrorPrinter());
builder.parse(ClassLoader.getSystemResourceAsStream("de/fhg/ipsi/oasys/mgn/spec/test.xml"));
        } catch (Exception e) {e.printStackTrace();}

and here are two schemas and a document:


test.xsd:
=========
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema";
            targetNamespace="http://xml.netbeans.org/examples/targetNS";
            xmlns="http://xml.netbeans.org/examples/targetNS";
            xmlns:ns2="http://xml.netbeans.org/examples/targetNS2";
            elementFormDefault="qualified">

<xsd:import namespace="http://xml.netbeans.org/examples/targetNS2";
schemaLocation="blatest2.xsd" />

<xsd:element name="r" type="test" />

<xsd:element name="r2" type="test" />


<xsd:complexType name="test" >
    <xsd:sequence>
        <xsd:element name="rootns1" type="ns2:Root" />
    </xsd:sequence>
</xsd:complexType>

</xsd:schema>

test2.xsd:
==========

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema";
            targetNamespace="http://xml.netbeans.org/examples/targetNS2";
            xmlns="http://xml.netbeans.org/examples/targetNS2";
            elementFormDefault="qualified">

<xsd:element name="rootns2" type="Root" />

<xsd:complexType name="Root" >
    <xsd:sequence>
        <xsd:element name="root" type="xsd:string" />
    </xsd:sequence>
</xsd:complexType>

</xsd:schema>

test.xml
========

<r xmlns='http://xml.netbeans.org/examples/targetNS'
   xmlns:ns2='http://xml.netbeans.org/examples/targetNS2'
  xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
  xsi:schemaLocation='http://xml.netbeans.org/examples/targetNS
file:/usr/local/home/pedjak/projects/mgn/src/de/fhg/ipsi/oasys/mgn/spec/test.xsd'>
<rootns1> 
    <ns2:root>bla </ns2:root></rootns1>
</r>


=======================

  I have tried to provide to factory.setAttribute an array of two
InputStreams, but it does not help. 

  Still any idea? Is is possible to do that under JAXP 1.2?

Predrag


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

Reply via email to