Hi Huan.


Hess Yvan wrote:

Hi,

I have to validate many XML documents against a XML schema that is always
the same. I use the following code to do the validation for each XML
document:

// Get document builder factory and set its properties
factory = DocumentBuilderFactory.newInstance();
factory.setAttribute("http://apache.org/xml/properties/schema/external-schem
aLocation", schemaNS + " " + schemaURL);
factory.setAttribute("http://apache.org/xml/features/validation/schema";, new
Boolean(true));
factory.setAttribute("http://xml.org/sax/features/validation";, new
Boolean(true));
factory.setAttribute("http://xml.org/sax/features/namespaces";, new
Boolean(true));

// Get document parser and set its error handler
errorHandler = new XMLToolsValidationErrorHandler();
parser = factory.newDocumentBuilder();
parser.setErrorHandler(errorHandler);

// Parse the document
dom = parser.parse(docStream);

In this situation, I  presume that the XML schema is always parsed and
"transformed" that unfortunly take time and I would like to optimize it.

My questions are:

- Is that right the XML schema is always parsed and "transformed" every
time I call parser.parse() method ?

- How can I optimize XML schema validation if I have every time the same
schema to use to validate many XML documents ? I would like to use something
like you can found into XSLT with precompiled stylesheet.

Xerces provides caching of grammers and by default grammers are not cached , please look in to the sample program xni/XMLGrammarBuilder.java provided with xerces . And as jeff mentioned refer to [1].

[1]http://xml.apache.org/xerces2-j/faq-grammars.html

Regards
venu


Thanks for your answer.

Yvan Hess


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]






--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to