You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by mr...@apache.org on 2009/03/08 19:50:01 UTC
svn commit: r751497 -
/xerces/java/trunk/src/org/apache/xerces/dom/ElementImpl.java
Author: mrglavas
Date: Sun Mar 8 18:50:01 2009
New Revision: 751497
URL: http://svn.apache.org/viewvc?rev=751497&view=rev
Log:
Fixing a couple bugs. When searching for the next or previous element
sibling we must retrieve the next or previous logical sibling before
entering the main while loop.
Modified:
xerces/java/trunk/src/org/apache/xerces/dom/ElementImpl.java
Modified: xerces/java/trunk/src/org/apache/xerces/dom/ElementImpl.java
URL: http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/dom/ElementImpl.java?rev=751497&r1=751496&r2=751497&view=diff
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/dom/ElementImpl.java (original)
+++ xerces/java/trunk/src/org/apache/xerces/dom/ElementImpl.java Sun Mar 8 18:50:01 2009
@@ -1237,7 +1237,7 @@
* Element Traversal Specification</a>
*/
public final Element getNextElementSibling() {
- Node n = getNextSibling();
+ Node n = getNextLogicalSibling(this);
while (n != null) {
switch (n.getNodeType()) {
case Node.ELEMENT_NODE:
@@ -1249,31 +1249,17 @@
}
break;
}
- Node next = n.getNextSibling();
- // If "n" has no following sibling and its parent is an entity reference node we
- // need to continue the search through the following siblings of the entity
- // reference as these are logically siblings of *this* element node.
- if (next == null) {
- Node parent = n.getParentNode();
- while (parent != null && parent.getNodeType() == Node.ENTITY_REFERENCE_NODE) {
- next = parent.getNextSibling();
- if (next != null) {
- break;
- }
- parent = parent.getParentNode();
- }
- }
- n = next;
+ n = getNextLogicalSibling(n);
}
return null;
} // getNextElementSibling():Element
-
+
/**
* @see <a href="http://www.w3.org/TR/2008/REC-ElementTraversal-20081222/#attribute-previousElementSibling">
* Element Traversal Specification</a>
*/
public final Element getPreviousElementSibling() {
- Node n = getPreviousSibling();
+ Node n = getPreviousLogicalSibling(this);
while (n != null) {
switch (n.getNodeType()) {
case Node.ELEMENT_NODE:
@@ -1285,21 +1271,7 @@
}
break;
}
- Node prev = n.getPreviousSibling();
- // If "n" has no previous sibling and its parent is an entity reference node we
- // need to continue the search through the previous siblings of the entity
- // reference as these are logically siblings of *this* element node.
- if (prev == null) {
- Node parent = n.getParentNode();
- while (parent != null && parent.getNodeType() == Node.ENTITY_REFERENCE_NODE) {
- prev = parent.getPreviousSibling();
- if (prev != null) {
- break;
- }
- parent = parent.getParentNode();
- }
- }
- n = prev;
+ n = getPreviousLogicalSibling(n);
}
return null;
} // getPreviousElementSibling():Element
@@ -1355,5 +1327,43 @@
}
return null;
} // getLastElementChild(Node):Element
+
+ // Returns the next logical sibling with respect to the given node.
+ private Node getNextLogicalSibling(Node n) {
+ Node next = n.getNextSibling();
+ // If "n" has no following sibling and its parent is an entity reference node we
+ // need to continue the search through the following siblings of the entity
+ // reference as these are logically siblings of the given node.
+ if (next == null) {
+ Node parent = n.getParentNode();
+ while (parent != null && parent.getNodeType() == Node.ENTITY_REFERENCE_NODE) {
+ next = parent.getNextSibling();
+ if (next != null) {
+ break;
+ }
+ parent = parent.getParentNode();
+ }
+ }
+ return next;
+ } // getNextLogicalSibling(Node):Node
+
+ // Returns the previous logical sibling with respect to the given node.
+ private Node getPreviousLogicalSibling(Node n) {
+ Node prev = n.getPreviousSibling();
+ // If "n" has no previous sibling and its parent is an entity reference node we
+ // need to continue the search through the previous siblings of the entity
+ // reference as these are logically siblings of the given node.
+ if (prev == null) {
+ Node parent = n.getParentNode();
+ while (parent != null && parent.getNodeType() == Node.ENTITY_REFERENCE_NODE) {
+ prev = parent.getPreviousSibling();
+ if (prev != null) {
+ break;
+ }
+ parent = parent.getParentNode();
+ }
+ }
+ return prev;
+ } // getPreviousLogicalSibling(Node):Node
} // class ElementImpl
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xerces.apache.org
For additional commands, e-mail: commits-help@xerces.apache.org