You might try reading this discussion on JAXP, XML Catalogs, and XSDs. I don't know that this will solve your problem, but it seems related ...
Mark Maxey Raytheon, Garland 580/2/P22-1 (972)205-5760 mark_r_ma...@raytheon.com From: "Ramirez, Paul M (388J)" <paul.m.rami...@jpl.nasa.gov> To: "j-users@xerces.apache.org" <j-users@xerces.apache.org> Date: 02/03/2012 09:18 AM Subject: XMLCatalogResolver Schema with Include Hi All, I'm having an issue with XML catalogs and validating an XML file based on lookups with URI elements. I believe the issue is coming down to resolving the include from one of my namespace schema. It could be that I'm not setting something but I just can't seem to figure it out. I believe the following example shows what I am talking about. If anyone can test it out please let me know if you are experiencing the same thing or know how or why it doesn't work. As a side note this works within a editor like Oxygen and everything resolves. foo.xsd: <?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault= "qualified" targetNamespace="http://foo.jpl.nasa.gov/foo" xmlns:foo=" http://foo.jpl.nasa.gov/foo"> <xs:include schemaLocation="http://foo.jpl.nasa.gov/foo-include.xsd"/> <xs:element name="first" type="xs:string"/> <xs:complexType name="name"> <xs:sequence> <xs:element ref="foo:first"/> <xs:element ref="foo:last"/> </xs:sequence> </xs:complexType> <xs:element name="name" type="foo:name"/> </xs:schema> foo.xsd-include.xsd: <?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault= "qualified" targetNamespace="http://foo.jpl.nasa.gov/foo"> <xs:element name="last" type="xs:string"/> </xs:schema> catalog-foo.xml: <?xml version="1.0" encoding="UTF-8"?> <catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog"> <!-- This is a sample --> <uri name="http://foo.jpl.nasa.gov/foo" uri=" file:///Users/pramirez/Desktop/catalog/foo.xsd"/> <system systemId="http://foo.jpl.nasa.gov/foo-include.xsd" uri=" file:///Users/pramirez/Desktop/catalog/includes/foo-include.xsd"/> </catalog> name.xml (purposely with an error so I can see if validation is occurring correctly): <?xml version="1.0" encoding="UTF-8"?> <name xmlns="http://foo.jpl.nasa.gov/foo"> <last></last> <first></first> </name> XMLTest.java: public class XMLTest { public static void main(String[] args) throws Exception { String[] catalogs = {args[0]}; XMLCatalogResolver resolver = new XMLCatalogResolver(); resolver.setCatalogList(catalogs); SchemaFactory sf = SchemaFactory.newInstance(XMLConstants. W3C_XML_SCHEMA_NS_URI); sf.setResourceResolver(resolver); Schema s = sf.newSchema(); Validator v = s.newValidator(); v.setResourceResolver(resolver); v.validate(new StreamSource(args[1])); } } The java program then is just called with the reference to the catalog-foo.xml and name.xml and I receive the following error: Exception in thread "main" org.xml.sax.SAXParseException: src-resolve: Cannot resolve the name 'foo:last' to a(n) 'element declaration' 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.reportSchemaError (Unknown Source) at org.apache.xerces.impl.xs.traversers.XSDHandler.getGlobalDecl(Unknown Source) at org.apache.xerces.impl.xs.traversers.XSDElementTraverser.traverseLocal (Unknown Source) at org.apache.xerces.impl.xs.traversers.XSDHandler.traverseLocalElements (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.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.XML11Configuration.parse(Unknown Source) at org.apache.xerces.jaxp.validation.StreamValidatorHelper.validate(Unknown Source) at org.apache.xerces.jaxp.validation.ValidatorImpl.validate(Unknown Source) at javax.xml.validation.Validator.validate(Validator.java:127) at gov.nasa.pds.tools.label.XMLTest.main(XMLTest.java:22) Now if I put the contents of foo-include.xsd into foo.xsd then everything is fine and validation occurs correctly. Any ideas what I am doing wrong. My understanding is the system entry in the catalog would allow the include to resolve. Thanks, Paul Ramirez
<<inline: graycol.gif>>