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 "Mukul Gandhi (Jira)" <xe...@xml.apache.org> on 2023/01/13 14:21:00 UTC

[jira] [Comment Edited] (XERCESJ-1754) XMLSchemaValidator reset no longer resets id validation caches

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

Mukul Gandhi edited comment on XERCESJ-1754 at 1/13/23 2:20 PM:
----------------------------------------------------------------

you wrote, "We perform the same validation multiple times re-using the same parser". Within your program, on different repetitions of XML schema validation, do you use same XML schema document and XML instance document every time?

Lets say, we've following outline (do you use the same kind of code pattern?) of XML schema validation Java program,

DocumentBuilderFactory parserFactory = DocumentBuilderFactory.newInstance();
parserFactory.setNamespaceAware(true);
DocumentBuilder parser = parserFactory.newDocumentBuilder();
Document document = parser.parse(new File("test.xml"));

SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);

Source schemaFile = new StreamSource(new File("test.xsd"));
Schema schema = factory.newSchema(schemaFile);

Validator validator = schema.newValidator();
validator.validate(new DOMSource(document));

When you say that you're, "re-using the same parser", do you reuse for example the Java object 'DocumentBuilder parser'? Are you using an XML dom parser within your program, or a different one?

Are you reusing any of the following Java objects as well : 'Schema schema', 'Validator validator'?

Are you using JAXP api as cited within this message?

Perhaps, after knowing answers of above questions, someone may attempt to solve the issues mentioned within this bug report.


was (Author: mukul_gandhi):
you wrote, "We perform the same validation multiple times re-using the same parser". Within your program, on different repetitions of XML schema validation, do you use same XML schema document and XML instance document every time?

Lets say, we've following outline (do you use the same kind of code pattern?) of XML schema validation Java program,

DocumentBuilderFactory parserFactory = DocumentBuilderFactory.newInstance();
parserFactory.setNamespaceAware(true);
DocumentBuilder parser = parserFactory.newDocumentBuilder();
Document document = parser.parse(new File("test.xml"));

SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);

Source schemaFile = new StreamSource(new File("test.xsd"));
Schema schema = factory.newSchema(schemaFile);

Validator validator = schema.newValidator();
validator.validate(new DOMSource(document));

When you say that you, "re-using the same parser", do you reuse for example the Java object 'DocumentBuilder parser'? Are you using an XML dom parser within your program, or a different one?

Are you reusing any of the following Java objects as well : 'Schema schema', 'Validator validator'?

Are you using JAXP api as cited within this message?

Perhaps, after knowing answers of above questions, someone may attempt to solve the issues mentioned within this bug report.

> 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-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-dev-help@xerces.apache.org