Uploaded image for project: 'Xerces2-J'
  1. Xerces2-J
  2. XERCESJ-1739

EntityResolver is not invoked for xsi:schemaLocation attribute

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Invalid
    • 2.12.1
    • None
    • None

    Description

      setEntityResolver on SAXParser is not being called to resolve xsi:schemaLocation.

      Example:

              class DummyResolver implements EntityResolver {

                  @Override
                  public InputSource resolveEntity(String publicId, String systemId) throws SAXException

      {                 throw new SAXException("Access denied.");             }

              }    

              // main()

              // Path schemaPath ...
              // Path dataPath ...

              SchemaFactory schemaFactory = SchemaFactory.newInstance(
                      "http://www.w3.org/XML/XMLSchema/v1.1");

              StreamSource schemaSource = new StreamSource(schemaPath.toFile());
              Schema schema = schemaFactory.newSchema(schemaSource);

              SAXParserFactory spf = SAXParserFactory.newInstance();
              spf.setSchema(schema);
              spf.setNamespaceAware(true);
              SAXParser sp = spf.newSAXParser();
          
              XMLReader parser = sp.getXMLReader();
              //parser.setErrorHandler(new SAXErrorHandler());
              //parser.setContentHandler(new TestHandler());
              parser.setEntityResolver( new DummyResolver());
              InputSource is = new InputSource(new FileInputStream(dataPath.toFile()));
              parser.parse(is);

       

      Schema (i.e. the file 'schemaPath' variable references in the code above)

      <?xml version="1.0" encoding="UTF-8" ?>
      <xs:schema 
          xmlns:xs="http://www.w3.org/2001/XMLSchema"
      >

          <!-- ROOT ELEMENT -->
          <xs:element name="SiebelMessage">
              <xs:complexType>
                  <xs:sequence>
                      <xs:element name="CaseNum" maxOccurs="7" type="xs:string" />
                      <xs:any minOccurs="0" />
                  </xs:sequence>
              </xs:complexType>
          </xs:element>

      </xs:schema>

       

      fod.xsd:

      <?xml version="1.0" encoding="UTF-8" ?>
      <xs:schema 
          xmlns:xs="http://www.w3.org/2001/XMLSchema"
          xmlns="http://intra.tpon.gov.on.ca/fod"
          targetNamespace="http://intra.tpon.gov.on.ca/fod"
      >
          <xs:element name="testElement" type="xs:integer" />

      </xs:schema>

       

      Instance:

      <?xml version="1.0" encoding="UTF-8" ?>

      <SiebelMessage 
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xmlns:fod="http://intra.fod.gov.on.ca"
          xsi:schemaLocation="http://intra.fod.gov.on.ca fod.xsd"
      >

          <CaseNum>1234</CaseNum>
          <CaseNum>1234</CaseNum>
          <CaseNum>1234</CaseNum>
          <fod:testElement>123</fod:testElement>
      </SiebelMessage>

       

      Result:

      Exception in thread "main" org.xml.sax.SAXException: Error: URI=[file:///C:/tpon/fod/schema/xerces_tests/test1/input.xml] Line=12: cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'fod:testElement'.

       

      Expected result was for xsi:schemaLocation to try resolve the fod namespace and call entity resolver to get the fod.xsd schema docment.

      Attachments

        Activity

          People

            Unassigned Unassigned
            bajwaya Yasir Bajwa
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: