You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by Revathi <re...@siptech.co.in> on 2003/01/30 08:08:53 UTC

AttributeIterator getNextNode() always returns the first attribute

Hi,

    I faced a problem using the compiler class . I am using an XPath
expression ( //*[contains(@*,'sometext')] ) . when the compile(int)
method is called I have printed out the expression value returned each
time . For my expression it returns

Expr : org.apache.xpath.axes.AttributeIterator@fb1f7
Expr : org.apache.xpath.axes.AttributeIterator@fb1f7
Expr : Text
Expr : Text
Expr : org.apache.xpath.functions.FuncContains@6d0338
Expr : org.apache.xpath.axes.DescendantIterator@6e70c7

In the compile method . when the compile(int) finally returns the value

org.apache.xpath.axes.DescendantIterator@6e70c7 .

The return value is set as the expression value for the XPath Expression
. when the XPath Expression is executed
org.apache.xpath.axes.DescendantIterator.nextNode(int) method is called
before the attributes can be set to the attribute iterator .

This is the stack trace ..
java.lang.Exception: Stack trace
 at java.lang.Thread.dumpStack(Thread.java:993)
 at org.apache.xpath.axes.AttributeIterator.getNextNode(Unknown Source)
 at org.apache.xpath.axes.BasicTestIterator.nextNode(Unknown Source)
 at org.apache.xpath.axes.NodeSequence.nextNode(Unknown Source)
 at org.apache.xpath.axes.NodeSequence.item(Unknown Source)
 at org.apache.xpath.objects.XNodeSet.str(Unknown Source)
 at org.apache.xpath.functions.FuncContains.execute(Unknown Source)
 at org.apache.xpath.axes.PredicatedNodeTest.executePredicates(Unknown
Source)
 at org.apache.xpath.axes.PredicatedNodeTest.acceptNode(Unknown Source)
 at org.apache.xpath.axes.DescendantIterator.nextNode(Unknown Source)
 at org.apache.xpath.axes.NodeSequence.nextNode(Unknown Source)
 at org.apache.xml.dtm.ref.DTMNodeIterator.nextNode(Unknown Source)
 at ApplyXPath1.doMain(ApplyXPath1.java:139)
 at ApplyXPath1.main(ApplyXPath1.java:188)

when the DescendantIterator.nextNode() method is called the acceptNode()
method of PredicatedTestNode always returns false since the
AttributeValues are not set in the AttributeIterator hence the result
will always be false . So the loop is executed till nextnode is NULL and
the value for m_fetched will be -1 when it comes out of the do-while
loop.  Only after this the function is executed and since the value of
m_fetched is -1 , AttributeIterator.getNextNode() method always returns
the first attribute and doesnot return the other attributes .

Is there anyway to set the values to the AttributeIterator and then call
the acceptnode() method ?

Thanks,
Revathi.