  | |  | Custom EntityResolver and xs:include not working | Custom EntityResolver and xs:include not working 2003-07-30 - By Volker Witzel
Dear all,
I have a problem with validating an XML string programmtically against a schema witch includes other schemas without a namespace.
A custom Entityresolver is put in place to find the schema instances. Please see attached files for saample XSD and a sample XML, which is used for JUnit testing.
The environment is as follows: user.xsd includes both smart-types.xsd and company.xsd user.xsd can be validated within WSAD 5, so it there finds and validates the external resources correctly. This makes me quite sure that the XSDs are fine.
The Java/Xerces Part: I do try to convert an XML InputSource to a Document with validation. sample code: public static Document convertToDocument(InputSource in, String xmlSchemaSource) throws TechnicalException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); try { DocumentBuilder builder = null; if (!StringHelper.isNullOrEmpty(xmlSchemaSource)) { factory.setNamespaceAware(true); factory.setValidating(true); factory.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA); factory.setAttribute(JAXP_SCHEMA_SOURCE, xmlSchemaSource); builder = factory.newDocumentBuilder(); builder.setErrorHandler(new SWFXMLErrorHandler()); builder.setEntityResolver(new XSDEntityResolver()); } return builder.parse(in);
and sample code from XSDEntityResolver: public InputSource resolveEntity(String publicID, String systemID) throws IOException, SAXException { if (systemID != null && systemID.endsWith(".xsd")) { String filename = systemID.substring(systemID.lastIndexOf(GlobalConstants.SEPARATOR_CHAR) + 1); return new InputSource(findSchemaInstance(filename)); } return null; //important ! }
The method "resolveEntity" is called three times (for each xsd file), each finding the correct XSD file and returning a valid Input source, so Xerces seems to parse the user.xsd correctly. So far so good, but then the following excpetion is thrown:
org.xml.sax.SAXParseException: src-resolve: Cannot resolve the name 'UserId' to a(n) type definition component. at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source) at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source) at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source) at org.apache.xerces.impl.xs.traversers.XSDHandler.reportSchemaError(Unknown Source) at org.apache.xerces.impl.xs.traversers.XSDHandler.getGlobalDecl(Unknown Source) at org.apache.xerces.impl.xs.traversers.XSDAttributeTraverser.traverseNamedAttr (Unknown Source) at org.apache.xerces.impl.xs.traversers.XSDAttributeTraverser.traverseLocal (Unknown Source) at org.apache.xerces.impl.xs.traversers.XSDAbstractTraverser .traverseAttrsAndAttrGrps(Unknown Source) at org.apache.xerces.impl.xs.traversers.XSDComplexTypeTraverser .processComplexContent(Unknown Source) at org.apache.xerces.impl.xs.traversers.XSDComplexTypeTraverser .traverseComplexTypeDecl(Unknown Source) at org.apache.xerces.impl.xs.traversers.XSDComplexTypeTraverser.traverseGlobal (Unknown Source) at org.apache.xerces.impl.xs.traversers.XSDHandler.traverseSchemas(Unknown Source) at org.apache.xerces.impl.xs.traversers.XSDHandler.parseSchema(Unknown Source) at org.apache.xerces.impl.xs.XMLSchemaLoader.loadSchema(Unknown Source) at org.apache.xerces.impl.xs.XMLSchemaLoader.processJAXPSchemaSource(Unknown Source) at org.apache.xerces.impl.xs.XMLSchemaLoader.loadSchema(Unknown Source) at org.apache.xerces.impl.xs.XMLSchemaValidator.findSchemaGrammar(Unknown Source) at org.apache.xerces.impl.xs.XMLSchemaValidator.handleStartElement(Unknown Source) at org.apache.xerces.impl.xs.XMLSchemaValidator.startElement(Unknown Source) at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source) at org.apache.xerces.impl.XMLNSDocumentScannerImpl$NSContentDispatcher .scanRootElementHook(Unknown Source) at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher .dispatch(Unknown Source) at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source) at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source) at org.apache.xerces.parsers.XMLParser.parse(Unknown Source) at org.apache.xerces.parsers.DOMParser.parse(Unknown Source) at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source) at com.schenker.swf.helper.DomUtils.convertToDocument(DomUtils.java:321) at com.schenker.swf.helper.DomUtils.convertToDocument(DomUtils.java:283) at com.schenker.dbsmart.authentication.datastructures.test.UserTest.setUp(UserTest .java:46)
I don't have a clue what's wrong. Perhaps a bug in Xerces? I already digged all appropriate newsgroups, without success. So you are my last resort.
Any help or hints greatly appreciated!
Volker.
--------------------------------------------------------------------- To unsubscribe, e-mail: xerces-j-user-unsubscribe@(protected) For additional commands, e-mail: xerces-j-user-help@(protected)
|
|
 |