You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by "Michael Glavassevich (Jira)" <xe...@xml.apache.org> on 2022/02/12 01:44:00 UTC

[jira] [Resolved] (XERCESJ-1739) EntityResolver is not invoked for xsi:schemaLocation attribute

     [ https://issues.apache.org/jira/browse/XERCESJ-1739?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Michael Glavassevich resolved XERCESJ-1739.
-------------------------------------------
    Resolution: Invalid

This is working as designed. The JAXP spec requires this behaviour. If you want XML schema documents to be loaded from xsi:schemaLocation attributes in the instance document, you need to use this method: https://xerces.apache.org/xerces2-j/javadocs/api/javax/xml/validation/SchemaFactory.html#newSchema() instead for creating the Schema object.

> EntityResolver is not invoked for xsi:schemaLocation attribute
> --------------------------------------------------------------
>
>                 Key: XERCESJ-1739
>                 URL: https://issues.apache.org/jira/browse/XERCESJ-1739
>             Project: Xerces2-J
>          Issue Type: Bug
>          Components: JAXP (javax.xml.validation)
>    Affects Versions: 2.12.1
>            Reporter: Yasir Bajwa
>            Priority: Minor
>
> 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|http://intra.fod.gov.on.ca/]"
>     xsi:schemaLocation="[http://intra.fod.gov.on.ca|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.



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

---------------------------------------------------------------------
To unsubscribe, e-mail: j-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-dev-help@xerces.apache.org