[ 
https://issues.apache.org/jira/browse/XERCESJ-1754?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17677474#comment-17677474
 ] 

Mukul Gandhi commented on XERCESJ-1754:
---------------------------------------

Within your original XML schema document, attached within this bug report 
(test.xsd), you specify following on the top most xs:schema element,

<xs:schema xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning"; 
vc:minVersion="1.1" ...       I believe, this alone is not sufficient with 
XercesJ to invoke an XML Schema 1.1 validation. To invoke XML Schema 1.1 
validation with XercesJ, it needs to be done via an API provided by XercesJ. 
For example as follows,

private static String saxParserFactoryClass = 
"org.apache.xerces.jaxp.SAXParserFactoryImpl";

SchemaFactory xsdSchemaFactory = 
SchemaFactory.newInstance(Constants.W3C_XML_SCHEMA11_NS_URI);
Schema xsdSchema = xsdSchemaFactory.newSchema(new StreamSource(xsdDocument));

SAXParserFactory saxParserFactory = 
SAXParserFactory.newInstance(saxParserFactoryClass, null);
saxParserFactory.setNamespaceAware(true);
saxParserFactory.setSchema(xsdSchema);

SAXParser saxParser = saxParserFactory.newSAXParser();
saxParser.parse(xmlDocument, new XmlParseErrorHandler());

I believe, that with XercesJ, we cannot select XML Schema 1.1 validation when 
parsing and validating directly with XMLReaderFactory and XMLReader (I think, 
only XML Schema 1.0 validation is possible via this method). Using XMLReader is 
essentially using XML document event handling like an XML SAX parser. Actually, 
a proper Java SAXParser (like, org.apache.xerces.parsers.SAXParser) has an 
underlying XMLReader that does SAX like XML document event handling.

Mainly, I wish to suggest that, you should use the real XercesJ SAX parser 
(i.e, org.apache.xerces.parsers.SAXParser) to select XML Schema 1.1 validation 
via XercesJ (using something, like the code pattern I've suggested above).

About your actual bug report within this thread, I've verified, and I agree 
that it seems to be a bug with XercesJ's XML Schema 1.1 validator when using 
with XercesJ's SAX parser.

i.e, when using two consecutive java statements like following,
saxParser.parse(xmlDocument, new XmlParseErrorHandler());
saxParser.parse(xmlDocument, new XmlParseErrorHandler());

the second statement, produces XML schema validation failure (but the first one 
doesn't).

As a workaround, you might do like following (i.e, you can create a new XML SAX 
parser instance for the 2nd and all subsequent parse(..) calls),

saxParser.parse(xmlDocument, new XmlParseErrorHandler());
saxParser = saxParserFactory.newSAXParser();
saxParser.parse(xmlDocument, new XmlParseErrorHandler());

The above workaround, may not be very elegant, but I don't see much performance 
overhead with above mentioned workaround.

And I could also verify that, not having 'return;' statement within XercesJ 
XMLSchemaValidator class's code that you've cited, seems to solve this bug for 
the XML Schema 1.1 validation. I could also verify that, XercesJ's XML Schema 
1.0 validator (that's available within XercesJ's XML Schema 1.1 distribution), 
is not affected by this bug.

Perhaps, someone could try fixing the issues, mentioned within this bug report, 
in the right way.

> XMLSchemaValidator reset no longer resets id validation caches
> --------------------------------------------------------------
>
>                 Key: XERCESJ-1754
>                 URL: https://issues.apache.org/jira/browse/XERCESJ-1754
>             Project: Xerces2-J
>          Issue Type: Bug
>          Components: XML Schema 1.1 Structures
>            Reporter: Radu Coravu
>            Priority: Major
>         Attachments: test.xml, test.xsd
>
>
> I validate an XML with an XML Schema 1.1 file.
> On the first validation the XML is reported valid.
> On the second validation I re-use the parser, the ID values inside elements 
> are reported as duplicate and I get errors like this reported:
> {code}Message: cvc-type.3.1.3: The value 'thing122' of element 'uid' is not 
> valid.{code}
> Looking at the method 
> org.apache.xerces.impl.xs.XMLSchemaValidator.reset(XMLComponentManager), 
> there is a fast return inside it:
> {code}        if (!parser_settings) {
>             // parser settings have not been changed
>             fValidationManager.addValidationState(fValidationState);
>             // the node limit on the SecurityManager may have changed so need 
> to refresh.
>             nodeFactory.reset();
>             // Re-parse external schema location properties.
>             XMLSchemaLoader.processExternalHints(
>                 fExternalSchemas,
>                 fExternalNoNamespaceSchema,
>                 fLocationPairs,
>                 fXSIErrorReporter.fErrorReporter);
>             return;
>         }{code}
> and this means all the code which for example cleared the IDs cache:
> {code}        // reset ID Context
>         if (fIDContext != null) {
>             fIDContext.clear();
>         }{code}
> is no longer executed.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

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

Reply via email to