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 Bill Michell <bi...@bbc.co.uk> on 2003/12/18 18:30:58 UTC

import of schema with DOCTYPE declaration

I'm trying to get xerces-j version "Xerces-J 2.1.0" (as embedded in Apple's WebObjects 5.2.2 - my application's standard platform) to parse and validate an XML document using a specific XML Schema, through jaxp calls.

Unfortunately the Schema document is not under my control (though I can make a local copy and tune it, of course).

I'm using the following code to set up a DocumentBuilder which will validate against the schema document:
	public static DocumentBuilderFactory documentBuilderFactory(String schemaUrl) {
		DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();
		factory=DocumentBuilderFactory.newInstance();
		factory.setCoalescing(true);
		factory.setExpandEntityReferences(true);
		factory.setNamespaceAware(true);
		factory.setIgnoringComments(false);
		factory.setIgnoringElementContentWhitespace(false);
		factory.setValidating(true);
		factory.setAttribute(
			"http://java.sun.com/xml/jaxp/properties/schemaLanguage",
			"http://www.w3.org/2001/XMLSchema");
		factory.setAttribute(
			"http://java.sun.com/xml/jaxp/properties/schemaSource",
			schemaUrl);
		return factory;		
	}

My problem is that the parsing fails with the following exception:
[2003-12-18 16:37:39 GMT] <WorkerThread0> src-import.0: Failed to read imported schema document 'http://www.w3.org/2001/03/xml.xsd'.
[2003-12-18 16:37:39 GMT] <WorkerThread0> src-resolve: Cannot resolve the name 'xml:lang' to a(n) attribute declaration component.
org.xml.sax.SAXParseException: src-resolve: Cannot resolve the name 'xml:lang' to a(n) attribute declaration component.
	at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:232)
	at org.apache.xerces.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:173)
	at org.apache.xerces.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:371)
	at org.apache.xerces.impl.xs.traversers.XSDHandler.reportSchemaError(XSDHandler.java:1937)
	at org.apache.xerces.impl.xs.traversers.XSDHandler.getGlobalDecl(XSDHandler.java:1046)
	at org.apache.xerces.impl.xs.traversers.XSDAttributeTraverser.traverseLocal(XSDAttributeTraverser.java:126)
	at org.apache.xerces.impl.xs.traversers.XSDAbstractTraverser.traverseAttrsAndAttrGrps(XSDAbstractTraverser.java:412)
	at org.apache.xerces.impl.xs.traversers.XSDComplexTypeTraverser.traverseSimpleContent(XSDComplexTypeTraverser.java:547)
	at org.apache.xerces.impl.xs.traversers.XSDComplexTypeTraverser.traverseComplexTypeDecl(XSDComplexTypeTraverser.java:270)
	at org.apache.xerces.impl.xs.traversers.XSDComplexTypeTraverser.traverseLocal(XSDComplexTypeTraverser.java:165)
	at org.apache.xerces.impl.xs.traversers.XSDElementTraverser.traverseNamedElement(XSDElementTraverser.java:335)
	at org.apache.xerces.impl.xs.traversers.XSDElementTraverser.traverseGlobal(XSDElementTraverser.java:226)
	at org.apache.xerces.impl.xs.traversers.XSDHandler.traverseSchemas(XSDHandler.java:938)
	at org.apache.xerces.impl.xs.traversers.XSDHandler.parseSchema(XSDHandler.java:395)
	at org.apache.xerces.impl.xs.XMLSchemaLoader.loadSchema(XMLSchemaLoader.java:490)
	at org.apache.xerces.impl.xs.XMLSchemaLoader.processJAXPSchemaSource(XMLSchemaLoader.java:589)
	at org.apache.xerces.impl.xs.XMLSchemaLoader.loadSchema(XMLSchemaLoader.java:488)
	at org.apache.xerces.impl.xs.XMLSchemaValidator.findSchemaGrammar(XMLSchemaValidator.java:2287)
	at org.apache.xerces.impl.xs.XMLSchemaValidator.handleStartElement(XMLSchemaValidator.java:1781)
	at org.apache.xerces.impl.xs.XMLSchemaValidator.startElement(XMLSchemaValidator.java:588)
	at org.apache.xerces.impl.XMLNamespaceBinder.handleStartElement(XMLNamespaceBinder.java:877)
	at org.apache.xerces.impl.XMLNamespaceBinder.startElement(XMLNamespaceBinder.java:569)
	at org.apache.xerces.impl.dtd.XMLDTDValidator.startElement(XMLDTDValidator.java:727)
	at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.java:759)
	at org.apache.xerces.impl.XMLDocumentScannerImpl$ContentDispatcher.scanRootElementHook(XMLDocumentScannerImpl.java:957)
	at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(XMLDocumentFragmentScannerImpl.java:1544)
	at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:329)
	at org.apache.xerces.parsers.DTDConfiguration.parse(DTDConfiguration.java:525)
	at org.apache.xerces.parsers.DTDConfiguration.parse(DTDConfiguration.java:581)
	at org.apache.xerces.parsers.XMLParser.parse(XMLParser.java:152)
	at org.apache.xerces.parsers.DOMParser.parse(DOMParser.java:253)
	at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:201)
<snip rest of stack trace>

By examining the schema documents, I find:
The main schema document contains the element:
<xs:import namespace="http://www.w3.org/XML/1998/namespace" schemaLocation="http://www.w3.org/2001/03/xml.xsd"/>

I believe this is so that we can use xml:lang attributes within the elements that we are defining.

http://www.w3.org/2001/03/xml.xsd contains the declaration:
<!DOCTYPE xs:schema PUBLIC "-//W3C//DTD XMLSCHEMA 200102//EN" "XMLSchema.dtd">

If I delete this <DOCTYPE> declaration from a local copy of xml.xsd, my exception goes away. Changing the path so that it explicitly points to a local copy of XMLSchema.dtd doesn't help. Neither does changing the path to explicitly point to a file on the w3 server.

Would someone please be kind enough to point me in the right direction.

-- 
Bill Michell


BBCi at http://www.bbc.co.uk/

This e-mail (and any attachments) is confidential and may contain
personal views which are not the views of the BBC unless specifically
stated.
If you have received it in error, please delete it from your system. 
Do not use, copy or disclose the information in any way nor act in
reliance on it and notify the sender immediately. Please note that the
BBC monitors e-mails sent or received. 
Further communication will signify your consent to this.