Dick Deneer <[EMAIL PROTECTED]> wrote on 07/09/2006 
01:11:26 PM:

> Thank you very much for this explanation. 
> I was not aware of the jira-1158 discussion. But I am very glad to 
> see that others have had their doubts also about this topic; this 
> make me think less stupid :)
>
> But I am still struggling on.
> In my XML tool you can browse the xml in tree and source view. In 
> the tree view there is a DOM behind and I am working with the Xerces
> 3 Dom revalidation.
> In the past I have tried to convert this to the JAXP Validator using
> a DOMSource, but there was a blocking issue: in case of error the 
> validator passes a SAXException with no reference to the current 
> element node. We already discussed this issue in the passed and you 
> were thinking about an extra property to solve this. If this is 
> already implemented I missed this.

It was implemented in Xerces 2.8.0. If your ErrorHandler has a reference 
to the Validator and you query the 
http://apache.org/xml/properties/dom/current-element-node property [1] the 
Validator will return the current element node that is being visited.
 
> In the source view I am working with sax. 
> While switching between source and dom view I want to reuse the 
> compiled grammars between them. 
>
> I did some tests with the validator api but I see a lot of problems:
> 
> - It looks very difficult to hand over a filled grammarpool to the 
> validator.  I thouht about just:  reading the grammars  from the 
> filled grammarpool,then  creating a Schema with the SchemaFactory 
> and then adding the grammars to the Schema which is by itself a 
> grammarpool (or is this in fact the bucket and not the real 
> grammarpool). But I displayed the Schema classes, made by the 
> schemaFactory and they differ depending on the number of schemas 
> supplied.  So I am afraid I cannot start with just an empty schema 
> instantiation.

Couldn't you just create the Schema from the SchemaFactory using all of 
sources that you would have used to populate the grammar pool? It's true 
that the Schema implementations in Xerces are backed by a grammar pool but 
you really shouldn't be trying to do anything with these grammar pools. 
They are only intended for consumption by the JAXP validator. If you try 
writing to them you'll find three of the four implementations are 
immutable and the fourth is a memory sensitive cache which releases 
grammars to the garbage collector in response to memory demand so the 
grammar you add might get tossed at some point.

> - Also I did a test with the LSResourceResolver with the following XML
> <purchaseOrder orderDate="1999-10-20" xmlns="http://tempuri.org/po.xsd";
>     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="
> http://tempuri.org/po.xsd C:\Temp\Schemas\apo.xsd">
> If I created a empty schema : Schema schema = factory.newSchema();
> the the resolver was called and I got the following output:
> DTD Support : false
> schema [EMAIL PROTECTED]
> validator has resource resolver [EMAIL PROTECTED]
> Validator Asking for resourece:
> --type                    http://www.w3.org/2001/XMLSchema
> --namespaceURI            http://tempuri.org/po.xsd
> --resolve Entity publicId null
> --resolve Entity systemId C:\Temp\Schemas\apo.xsd
> --baseURI                 
file:///Users/dick/Documents/workspace/Tester/po.xml
> validator warning org.xml.sax.SAXParseException: schema_reference.4:
> Failed to read schema document 'C:\Temp\Schemas\apo.xsd', because 1)
> could not find the document; 2) the document could not be read; 3) 
> the root element of the document is not <xsd:schema>.
> validator error org.xml.sax.SAXParseException: cvc-elt.1: Cannot 
> find the declaration of element 'purchaseOrder'.
> cause null
> getException null
> org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the 
> declaration of element 'purchaseOrder'.
> 
> f I created a nonempty schema : Schema schema = factory.
> newSchema(new StreamSource[]{pe});
> The schema has another namespace then referenced in the xml.
> then the resolver was NOT called and I got the following output:
> DTD Support : false
> schema [EMAIL PROTECTED]
> schema is an XMLGrammarPool
> --found XSGrammar in pool---
> Grammar is instanceof XMLSchemaDescription
> XMLSchemaDescription.getLiteralSystemId file:
> ///Users/dick/Documents/workspace/Tester/personal.xsd
> 
> validator has resource resolver [EMAIL PROTECTED]
> validator error org.xml.sax.SAXParseException: cvc-elt.1: Cannot 
> find the declaration of element 'purchaseOrder'.
> cause null
> getException null
> org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the 
> declaration of element 'purchaseOrder'
> 
> When I als add the referenced schema: Schema schema = factory.
> newSchema(new StreamSource[]{pe,po});
> then the instace is checked and error are repotred as expected.
> DTD Support : false
> schema [EMAIL PROTECTED]
> validator has resource resolver [EMAIL PROTECTED]
> validator error org.xml.sax.SAXParseException: cvc-pattern-valid: 
> Value '926-AAX' is not facet-valid with respect to pattern '\d{3}-
> [A-Z]{2}' for type 'SKU'.
> cause null
> getException null
> org.xml.sax.SAXParseException: cvc-pattern-valid: Value '926-AAX' is
> not facet-valid with respect to pattern '\d{3}-[A-Z]{2}' for type 'SKU'.
> 
> I do not understand why the resolver is not called in the second case ?

The Schema returned by SchemaFactory.newSchema() [2] has different 
semantics to the ones returned by the other newSchema() [3] methods. Think 
of the SchemaFactory.newSchema() schema as open, rather than empty. It 
pulls in schema components during validation from the schema locations 
specified in the documents and/or the sources returned by your 
LSResourceResolver if you registered one with the Validator. The Schema 
objects returned by the other newSchema() methods are closed (or fully 
composed). Only the schema components which were loaded by the 
SchemaFactory are used for validation. Your LSResourceResolver won't be 
called during validation and any schema location hints in the document 
will be ignored.

> I attached my test resources.

[1] 
http://xerces.apache.org/xerces2-j/properties.html#dom.current-element-node
[2] 
http://xerces.apache.org/xerces2-j/javadocs/api/javax/xml/validation/SchemaFactory.html#newSchema()
[3] 
http://xerces.apache.org/xerces2-j/javadocs/api/javax/xml/validation/SchemaFactory.html#newSchema(javax.xml.transform.Source[])

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: [EMAIL PROTECTED]
E-mail: [EMAIL PROTECTED]

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

Reply via email to