0

I've tried creating a SAXParser, but any xsi:schemaLocation attributes in the instance document are ignored. Does Xerces not support this feature when using JAXP?

import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
...

SAXParserFactory spf = SAXParserFactory.newInstance();
spf.setSchema(schema);      // schema already created beforehand
spf.setNamespaceAware(true);

SAXParser sp = spf.newSAXParser();
                            
XMLReader parser = sp.getXMLReader();
parser.setEntityResolver( new DefaultResolver());    // the entity resolver never gets invoked
parser.setErrorHandler(new SAXErrorHandler()); 
parser.setContentHandler(new TestHandler());
parser.parse(new InputSource(new FileInputStream(dataPath.toFile())));

So everything works in terms of parsing and validating the document, except when there are xsi:schemaLocation attributes, these are completely getting ignored.

If I use Xerces directly, it will invoke its entity resolver.

yas
  • 3,520
  • 4
  • 25
  • 38

1 Answers1

0

This is correct behavior as per JAXP specification.

To use xsi:schemaLocaton or xsi:noNamespceSchemaLocation hints during validation, the method newSchema should be used instead of newSchema(schema).

yas
  • 3,520
  • 4
  • 25
  • 38