You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Carla Spruit <ca...@x-hive.com> on 2007/05/09 10:59:08 UTC

Validation of DOM nodes

Hi,

 

We would like to use the Xerces validation implementation to validate a
DOM Document.

(see
http://xerces.apache.org/xerces2-j/javadocs/api/javax/xml/validation/Val
idator.html)

 

In Xerces 2.6.2 (included with java 1.5.0) the
org.apache.xml.serializer.TreeWalker traverse method is used to traverse
the DOM structure during validation.

 

The following piece of code of this class shows that nodes are compared
by using the equals method:

  

public void traverse(Node pos) throws org.xml.sax.SAXException {

  this.m_contentHandler.startDocument();

  Node top = pos;

  while (null != pos) {

      startNode(pos);

      Node nextNode = pos.getFirstChild();

      while (null == nextNode) {

        endNode(pos);

        if (top.equals(pos))

          break;  

 

   .....

}

 

I do not exactly know when this is changed, but at least from Xerces
2.7.1, the org.apache.xerces.jaxp.validation.DOMValidatorHelper validate
method now handles the traversal of the DOM Document.

Unfortunately, the node test 'top.equals(pos)' is now replaced by the
test 'top == pos'. Our DOM implementation does not work with the "=="
comparison so we can no longer use the validation API to validate DOM
structures. We are aware of the fact that the DOM specs do not say
anything about node comparisons except the DOM level 3 functions
isSameNode and isEqualNode. 

Is there any other way to validate DOM structures with XML Schema
without modification of the DOM document and without serializing and
reparsing the document? (the DOM level 3 normalizeDocument function is
not an option because it may modify the DOM).

 

We would also like to be able to filter out nodes before validation. I
have read the http://marc.info/?l=xerces-j-user&m=117758843732534&w=2
conversation but was unable to find a way to validate a 'filtered' DOM
structure. 

 

Is there any chance that you will change the validation traversal
behavior in the near future?

 

Thanks,

 

Carla Spruit

 

 

 

 

 

 


RE: Validation of DOM nodes

Posted by Carla Spruit <ca...@x-hive.com>.
Hi Michael,

Thank you for fixing this!

Kind regards,

Carla

https://issues.apache.org/jira/browse/XERCESJ-1249?page=com.atlassian.jira.p
lugin.system.issuetabpanels:all-tabpanel


-----Original Message-----
From: Michael Glavassevich [mailto:mrglavas@ca.ibm.com] 
Sent: Wednesday, May 09, 2007 5:36 PM
To: j-users@xerces.apache.org
Subject: Re: Validation of DOM nodes

Hi Carla,

The code you're looking at is Sun's fork of the codebase. Apache Xerces 
has never called into org.apache.xml.serializer.TreeWalker to do the 
traversal. The implementation in Xerces (since 2.7.0 when it was 
introduced) was written so that it is capable of validating Nodes from a 
DOM Level 2 implementation. It currently doesn't call any methods (such as 
isSameNode()) that are only available in DOM Level 3. There was a similar 
issue in the DOM Level 2 TreeWalker [1] which I fixed [2] last year. The 
same fix could be applied here.

Thanks.

[1] http://issues.apache.org/jira/browse/XERCESJ-1127
[2] 
http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/dom/Tre
eWalkerImpl.java?revision=371588&view=markup

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org

"Carla Spruit" <ca...@x-hive.com> wrote on 05/09/2007 04:59:08 AM:

> Hi,
> 
> We would like to use the Xerces validation implementation to 
> validate a DOM Document.
> (see http://xerces.apache.org/xerces2-
> j/javadocs/api/javax/xml/validation/Validator.html)
> 
> In Xerces 2.6.2 (included with java 1.5.0) the org.apache.xml.
> serializer.TreeWalker traverse method is used to traverse the DOM 
> structure during validation.
> 
> The following piece of code of this class shows that nodes are 
> compared by using the equals method:
> 
> public void traverse(Node pos) throws org.xml.sax.SAXException {
>   this.m_contentHandler.startDocument();
>   Node top = pos;
>   while (null != pos) {
>       startNode(pos);
>       Node nextNode = pos.getFirstChild();
>       while (null == nextNode) {
>         endNode(pos);
>         if (top.equals(pos))
>           break; 
> 
>    ?..
> }
> 
> I do not exactly know when this is changed, but at least from Xerces
> 2.7.1, the org.apache.xerces.jaxp.validation.DOMValidatorHelper 
> validate method now handles the traversal of the DOM Document.
> Unfortunately, the node test ?top.equals(pos)? is now replaced by 
> the test ?top == pos?. Our DOM implementation does not work with the
> ?==? comparison so we can no longer use the validation API to 
> validate DOM structures. We are aware of the fact that the DOM specs
> do not say anything about node comparisons except the DOM level 3 
> functions isSameNode and isEqualNode. 
> Is there any other way to validate DOM structures with XML Schema 
> without modification of the DOM document and without serializing and
> reparsing the document? (the DOM level 3 normalizeDocument function 
> is not an option because it may modify the DOM).
> 
> We would also like to be able to filter out nodes before validation.
> I have read the http://marc.info/?l=xerces-j-user&m=117758843732534&w=2
> conversation but was unable to find a way to validate a ?filtered? 
> DOM structure. 
> 
> Is there any chance that you will change the validation traversal 
> behavior in the near future?
> 
> Thanks,
> 
> Carla Spruit

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



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


Re: Validation of DOM nodes

Posted by Michael Glavassevich <mr...@ca.ibm.com>.
Hi Carla,

The code you're looking at is Sun's fork of the codebase. Apache Xerces 
has never called into org.apache.xml.serializer.TreeWalker to do the 
traversal. The implementation in Xerces (since 2.7.0 when it was 
introduced) was written so that it is capable of validating Nodes from a 
DOM Level 2 implementation. It currently doesn't call any methods (such as 
isSameNode()) that are only available in DOM Level 3. There was a similar 
issue in the DOM Level 2 TreeWalker [1] which I fixed [2] last year. The 
same fix could be applied here.

Thanks.

[1] http://issues.apache.org/jira/browse/XERCESJ-1127
[2] 
http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/dom/TreeWalkerImpl.java?revision=371588&view=markup

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org

"Carla Spruit" <ca...@x-hive.com> wrote on 05/09/2007 04:59:08 AM:

> Hi,
> 
> We would like to use the Xerces validation implementation to 
> validate a DOM Document.
> (see http://xerces.apache.org/xerces2-
> j/javadocs/api/javax/xml/validation/Validator.html)
> 
> In Xerces 2.6.2 (included with java 1.5.0) the org.apache.xml.
> serializer.TreeWalker traverse method is used to traverse the DOM 
> structure during validation.
> 
> The following piece of code of this class shows that nodes are 
> compared by using the equals method:
> 
> public void traverse(Node pos) throws org.xml.sax.SAXException {
>   this.m_contentHandler.startDocument();
>   Node top = pos;
>   while (null != pos) {
>       startNode(pos);
>       Node nextNode = pos.getFirstChild();
>       while (null == nextNode) {
>         endNode(pos);
>         if (top.equals(pos))
>           break; 
> 
>    ?..
> }
> 
> I do not exactly know when this is changed, but at least from Xerces
> 2.7.1, the org.apache.xerces.jaxp.validation.DOMValidatorHelper 
> validate method now handles the traversal of the DOM Document.
> Unfortunately, the node test ?top.equals(pos)? is now replaced by 
> the test ?top == pos?. Our DOM implementation does not work with the
> ?==? comparison so we can no longer use the validation API to 
> validate DOM structures. We are aware of the fact that the DOM specs
> do not say anything about node comparisons except the DOM level 3 
> functions isSameNode and isEqualNode. 
> Is there any other way to validate DOM structures with XML Schema 
> without modification of the DOM document and without serializing and
> reparsing the document? (the DOM level 3 normalizeDocument function 
> is not an option because it may modify the DOM).
> 
> We would also like to be able to filter out nodes before validation.
> I have read the http://marc.info/?l=xerces-j-user&m=117758843732534&w=2
> conversation but was unable to find a way to validate a ?filtered? 
> DOM structure. 
> 
> Is there any chance that you will change the validation traversal 
> behavior in the near future?
> 
> Thanks,
> 
> Carla Spruit

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