You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Alasdair Thomson <al...@gzunk.com> on 2004/07/29 01:19:06 UTC

Validaing XML documents with linked XSchema documents

I'm attempting to validate a document using linked XSchema documents 
(using xs:include) and it fails, not finding the linked documents.  If I 
re-write the schema to be in a single document, there is no problems. 
Unfortunately I need to be able to validate the document using linked 
schema documents (stored locally)

Here's hoping someone can tell me what I'm doing wrong:

Schema Document 1:

<xs:schema elementFormDefault="qualified" xml:lang="EN"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://gzunk.com/first"
    xmlns="http://gzunk.com/first">
   
    <xs:include schemaLocation="tschema2.xsd"/>
   
    <xs:element name="document">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="pages"/>
            </xs:sequence>
        </xs:complexType>           
    </xs:element>
</xs:schema>

Schema Document 2:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema elementFormDefault="qualified" xml:lang="EN"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://gzunk.com/first"
    xmlns="http://gzunk.com/first">
   
    <xs:element name="pages">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="paragraph" maxOccurs="unbounded"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
   
    <xs:element name="paragraph" type="xs:string"/>
 
</xs:schema>

And the code:

            DocumentBuilderFactory dbf = 
DocumentBuilderFactory.newInstance();
            dbf.setValidating(true);
            dbf.setNamespaceAware(true);
            dbf.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
           
            InputStream schema = 
getClass().getClassLoader().getResourceAsStream("tschema.xsd");
            dbf.setAttribute(JAXP_SCHEMA_SOURCE, "schema");
           
            DocumentBuilder domParser = dbf.newDocumentBuilder();
            domParser.setErrorHandler(this);
           
            InputStream doc = 
getClass().getClassLoader().getResourceAsStream("first.xml");
            Document document = domParser.parse(doc);
           
If anyone can advise, please do!

Thanks

Alasdair

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


Re: Validaing XML documents with linked XSchema documents

Posted by George Cristian Bina <ge...@sync.ro>.
Hi Alasdair,

I think the problem is that you use a relative location for your 
included schema and you do not provide a system id to the parser, you 
use only input streams which do not carry any location info.

Hope that helps,
George
-----------------------------------------------
George Cristian Bina
<oXygen/> XML Editor & XSLT Editor/Debugger
http://www.oxygenxml.com


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org