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 "Ramirez, Paul M (388J)" <pa...@jpl.nasa.gov> on 2012/02/03 16:17:18 UTC

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

Re: XMLCatalogResolver Schema with Include

Posted by "Ramirez, Paul M (388J)" <pa...@jpl.nasa.gov>.
Michael that was exactly what I was looking for.

Thanks for the great help.

--Paul

On Feb 5, 2012, at 9:11 PM, "Michael Glavassevich" <mr...@ca.ibm.com>> wrote:


Paul,

The XMLCatalogResolver is working as documented / designed. Users are encouraged to extend this class if the default behaviour isn't what they desire.

If you register your extension as an XNI entity resolver, you could cast the XMLResourceIdentifier to an XMLSchemaDescription [1] and ignore the namespace when getContextType() equals XMLSchemaDescription.CONTEXT_INCLUDE.

Thanks.

[1] http://xerces.apache.org/xerces2-j/javadocs/xni/org/apache/xerces/xni/grammars/XMLSchemaDescription.html

Michael Glavassevich
XML Technologies and WAS Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com<ma...@ca.ibm.com>
E-mail: mrglavas@apache.org<ma...@apache.org>

"Ramirez, Paul M (388J)" <pa...@jpl.nasa.gov>> wrote on 02/05/2012 02:56:59 PM:

> Hey Michael,
>
> Thanks for your feedback. It ended up being the resolveResource
> method that was overridden. It starts out with the following:
>
>     public LSInput resolveResource(String type, String namespaceURI,
>         String publicId, String systemId, String baseURI) {
>
>         String resolvedId = null;
>         try {
>             // The namespace is useful for resolving namespace aware
>             // grammars such as XML schema. Let it take precedence over
>             // the external identifier if one exists.
>             if (namespaceURI != null) {
>                 resolvedId = resolveURI(namespaceURI);
>             }
>                 ...
>                 ...
> }
>
> So all I needed to do was set the namespace to null when a systemId
> was present and then call this method. That said, I'm not sure I
> want this to be the behavior and am wondering if this can be solved
> somewhere else with a patch. It seems as though when the xs:include
> is being encountered its namespace is being set to the namespace in
> which it is encountered. What seemingly should happen is that the
> include should not need to be associated with a namespace; that way
> it won't get resolved to a URI element in a catalog.
>
> Any thoughts on this? Do you know where I could look to deduce this
> issue further. I'm just not sure I'm comfortable going with the
> systemId every time its specified and thats what would happen with
> solving at the catalog level. I could be wrong and this could be fine.
>
> Also does this seem like something that should be patched in Xerces.
> If so when I figure it out I can create a Jira issue and submit a patch.
>
> Thanks,
> Paul Ramirez
>
> On Feb 3, 2012, at 12:20 PM, Michael Glavassevich wrote:
>
> You might also want to extend the XMLCatalogResolver and override
> its core resolveIdentifier() method. The base method won't make any
> distinction between your main schema document and the include and is
> probably always returning the URI entry from the catalog since the
> namespace is given higher precedence than the schema location.
>
> Thanks.
>
> Michael Glavassevich
> XML Technologies and WAS Development
> IBM Toronto Lab
> E-mail: mrglavas@ca.ibm.com<ma...@ca.ibm.com>
> E-mail: mrglavas@apache.org<ma...@apache.org>
>
> Mark R Maxey <Ma...@raytheon.com>> wrote on 02/03/2012 02:25:36 PM:
>
> > 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_Maxey@Raytheon.com<ma...@Raytheon.com>
> >
> > [image removed] "Ramirez, Paul M (388J)" ---02/03/2012 09:18:06
> > AM---Hi All, I'm having an issue with XML catalogs and validating an
> > XML file based on lookups with URI e
> >
> > From: "Ramirez, Paul M (388J)" <pa...@jpl.nasa.gov>>
> > To: "j-users@xerces.apache.org<ma...@xerces.apache.org>" <j-...@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
> everythingresolves.
> >
> > 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

Re: XMLCatalogResolver Schema with Include

Posted by Michael Glavassevich <mr...@ca.ibm.com>.
Paul,

The XMLCatalogResolver is working as documented / designed. Users are
encouraged to extend this class if the default behaviour isn't what they
desire.

If you register your extension as an XNI entity resolver, you could cast
the XMLResourceIdentifier to an XMLSchemaDescription [1] and ignore the
namespace when getContextType() equals
XMLSchemaDescription.CONTEXT_INCLUDE.

Thanks.

[1]
http://xerces.apache.org/xerces2-j/javadocs/xni/org/apache/xerces/xni/grammars/XMLSchemaDescription.html

Michael Glavassevich
XML Technologies and WAS Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org

"Ramirez, Paul M (388J)" <pa...@jpl.nasa.gov> wrote on 02/05/2012
02:56:59 PM:

> Hey Michael,
>
> Thanks for your feedback. It ended up being the resolveResource
> method that was overridden. It starts out with the following:
>
>     public LSInput resolveResource(String type, String namespaceURI,
>         String publicId, String systemId, String baseURI) {
>
>         String resolvedId = null;
>         try {
>             // The namespace is useful for resolving namespace aware
>             // grammars such as XML schema. Let it take precedence over
>             // the external identifier if one exists.
>             if (namespaceURI != null) {
>                 resolvedId = resolveURI(namespaceURI);
>             }
>                 ...
>                 ...
> }
>
> So all I needed to do was set the namespace to null when a systemId
> was present and then call this method. That said, I'm not sure I
> want this to be the behavior and am wondering if this can be solved
> somewhere else with a patch. It seems as though when the xs:include
> is being encountered its namespace is being set to the namespace in
> which it is encountered. What seemingly should happen is that the
> include should not need to be associated with a namespace; that way
> it won't get resolved to a URI element in a catalog.
>
> Any thoughts on this? Do you know where I could look to deduce this
> issue further. I'm just not sure I'm comfortable going with the
> systemId every time its specified and thats what would happen with
> solving at the catalog level. I could be wrong and this could be fine.
>
> Also does this seem like something that should be patched in Xerces.
> If so when I figure it out I can create a Jira issue and submit a patch.
>
> Thanks,
> Paul Ramirez
>
> On Feb 3, 2012, at 12:20 PM, Michael Glavassevich wrote:
>
> You might also want to extend the XMLCatalogResolver and override
> its core resolveIdentifier() method. The base method won't make any
> distinction between your main schema document and the include and is
> probably always returning the URI entry from the catalog since the
> namespace is given higher precedence than the schema location.
>
> Thanks.
>
> Michael Glavassevich
> XML Technologies and WAS Development
> IBM Toronto Lab
> E-mail: mrglavas@ca.ibm.com
> E-mail: mrglavas@apache.org
>
> Mark R Maxey <Ma...@raytheon.com> wrote on 02/03/2012 02:25:36 PM:
>
> > 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_Maxey@Raytheon.com
> >
> > [image removed] "Ramirez, Paul M (388J)" ---02/03/2012 09:18:06
> > AM---Hi All, I'm having an issue with XML catalogs and validating an
> > XML file based on lookups with URI e
> >
> > From: "Ramirez, Paul M (388J)" <pa...@jpl.nasa.gov>
> > To: "j-users@xerces.apache.org" <j-...@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
> everythingresolves.
> >
> > 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

Re: XMLCatalogResolver Schema with Include

Posted by "Ramirez, Paul M (388J)" <pa...@jpl.nasa.gov>.
Hey Michael,

In case you or others were interested here is the simple change I have:

public class XMLCatalogResolver extends org.apache.xerces.util.XMLCatalogResolver {

  public LSInput resolveResource(String type, String namespaceURI,
      String publicId, String systemId, String baseURI) {
    return (systemId == null) ? super.resolveResource(type, namespaceURI,
        publicId, systemId, baseURI) : super.resolveResource(type, null,
        publicId, systemId, baseURI);
  }

}

As I said though figuring out why this happens upstream is something I'd like to do. I'm just not as familiar with the Xerces code base so if you or anyone else had an idea of where to start it would be great.

Thanks,
Paul


On Feb 5, 2012, at 11:56 AM, Ramirez, Paul M (388J) wrote:

Hey Michael,

Thanks for your feedback. It ended up being the resolveResource method that was overridden. It starts out with the following:


    public LSInput resolveResource(String type, String namespaceURI,
        String publicId, String systemId, String baseURI) {

        String resolvedId = null;

        try {

            // The namespace is useful for resolving namespace aware
            // grammars such as XML schema. Let it take precedence over
            // the external identifier if one exists.
            if (namespaceURI != null) {
                resolvedId = resolveURI(namespaceURI);
            }

                ...
                ...
}

So all I needed to do was set the namespace to null when a systemId was present and then call this method. That said, I'm not sure I want this to be the behavior and am wondering if this can be solved somewhere else with a patch. It seems as though when the xs:include is being encountered its namespace is being set to the namespace in which it is encountered. What seemingly should happen is that the include should not need to be associated with a namespace; that way it won't get resolved to a URI element in a catalog.

Any thoughts on this? Do you know where I could look to deduce this issue further. I'm just not sure I'm comfortable going with the systemId every time its specified and thats what would happen with solving at the catalog level. I could be wrong and this could be fine.

Also does this seem like something that should be patched in Xerces. If so when I figure it out I can create a Jira issue and submit a patch.

Thanks,
Paul Ramirez


On Feb 3, 2012, at 12:20 PM, Michael Glavassevich wrote:


You might also want to extend the XMLCatalogResolver and override its core resolveIdentifier() method. The base method won't make any distinction between your main schema document and the include and is probably always returning the URI entry from the catalog since the namespace is given higher precedence than the schema location.

Thanks.

Michael Glavassevich
XML Technologies and WAS Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com<ma...@ca.ibm.com>
E-mail: mrglavas@apache.org<ma...@apache.org>

Mark R Maxey <Ma...@raytheon.com>> wrote on 02/03/2012 02:25:36 PM:

> 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_Maxey@Raytheon.com<ma...@Raytheon.com>
>
> [image removed] "Ramirez, Paul M (388J)" ---02/03/2012 09:18:06
> AM---Hi All, I'm having an issue with XML catalogs and validating an
> XML file based on lookups with URI e
>
> From: "Ramirez, Paul M (388J)" <pa...@jpl.nasa.gov>>
> To: "j-users@xerces.apache.org<ma...@xerces.apache.org>" <j-...@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 everythingresolves.
>
> 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



Re: XMLCatalogResolver Schema with Include

Posted by "Ramirez, Paul M (388J)" <pa...@jpl.nasa.gov>.
Hey Michael,

Thanks for your feedback. It ended up being the resolveResource method that was overridden. It starts out with the following:


    public LSInput resolveResource(String type, String namespaceURI,
        String publicId, String systemId, String baseURI) {

        String resolvedId = null;

        try {

            // The namespace is useful for resolving namespace aware
            // grammars such as XML schema. Let it take precedence over
            // the external identifier if one exists.
            if (namespaceURI != null) {
                resolvedId = resolveURI(namespaceURI);
            }

                ...
                ...
}

So all I needed to do was set the namespace to null when a systemId was present and then call this method. That said, I'm not sure I want this to be the behavior and am wondering if this can be solved somewhere else with a patch. It seems as though when the xs:include is being encountered its namespace is being set to the namespace in which it is encountered. What seemingly should happen is that the include should not need to be associated with a namespace; that way it won't get resolved to a URI element in a catalog.

Any thoughts on this? Do you know where I could look to deduce this issue further. I'm just not sure I'm comfortable going with the systemId every time its specified and thats what would happen with solving at the catalog level. I could be wrong and this could be fine.

Also does this seem like something that should be patched in Xerces. If so when I figure it out I can create a Jira issue and submit a patch.

Thanks,
Paul Ramirez


On Feb 3, 2012, at 12:20 PM, Michael Glavassevich wrote:


You might also want to extend the XMLCatalogResolver and override its core resolveIdentifier() method. The base method won't make any distinction between your main schema document and the include and is probably always returning the URI entry from the catalog since the namespace is given higher precedence than the schema location.

Thanks.

Michael Glavassevich
XML Technologies and WAS Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com<ma...@ca.ibm.com>
E-mail: mrglavas@apache.org<ma...@apache.org>

Mark R Maxey <Ma...@raytheon.com>> wrote on 02/03/2012 02:25:36 PM:

> 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_Maxey@Raytheon.com<ma...@Raytheon.com>
>
> [image removed] "Ramirez, Paul M (388J)" ---02/03/2012 09:18:06
> AM---Hi All, I'm having an issue with XML catalogs and validating an
> XML file based on lookups with URI e
>
> From: "Ramirez, Paul M (388J)" <pa...@jpl.nasa.gov>>
> To: "j-users@xerces.apache.org<ma...@xerces.apache.org>" <j-...@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 everythingresolves.
>
> 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


Re: XMLCatalogResolver Schema with Include

Posted by Michael Glavassevich <mr...@ca.ibm.com>.
You might also want to extend the XMLCatalogResolver and override its core
resolveIdentifier() method. The base method won't make any distinction
between your main schema document and the include and is probably always
returning the URI entry from the catalog since the namespace is given
higher precedence than the schema location.

Thanks.

Michael Glavassevich
XML Technologies and WAS Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org

Mark R Maxey <Ma...@raytheon.com> wrote on 02/03/2012 02:25:36 PM:

> 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_Maxey@Raytheon.com
>
> [image removed] "Ramirez, Paul M (388J)" ---02/03/2012 09:18:06
> AM---Hi All, I'm having an issue with XML catalogs and validating an
> XML file based on lookups with URI e
>
> From: "Ramirez, Paul M (388J)" <pa...@jpl.nasa.gov>
> To: "j-users@xerces.apache.org" <j-...@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
everythingresolves.
>
> 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

Re: XMLCatalogResolver Schema with Include

Posted by Mark R Maxey <Ma...@raytheon.com>.
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_Maxey@Raytheon.com



From:	"Ramirez, Paul M (388J)" <pa...@jpl.nasa.gov>
To:	"j-users@xerces.apache.org" <j-...@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