XPATH vs DOM tests acomplishied

hi, i performed some test trying to select one node in a document with 10000 nodes (<name first="ssss" last="sss">) and the test said:

[bold]Using xpath[/bold]

String xpath ="/doc/name[@first=\"Rodrigo\"]";

Node node = XPathAPI.selectSingleNode(doc, xpath);

[bold]it delay like 1970 milliseconds[/bold]

[bold]Using dom[/bold]

NodeList nodeList = (NodeList)doc.getElementsByTagName("name");

int length = nodeList.getLength();

for (int i = 0; i < length; i++){

Element node = (Element)nodeList.item(i);

String name = node.getAttribute("first");

if (name.equals("Rodrigo")){

break;

}

}

[bold]it delay like 1010 milliseconds[/bold]

HOW CAN IT BE ?

xpath is more slower than dom ?

thanks

Rodrigo Gonzalez Asensio

Researcher & Developer

Buenos Aires - Argentina

[1315 byte] By [redjat] at [2007-9-26 2:09:00]
# 1

Hello Rodrigo,

I shall not be surprised with your result. DOM builds a tree and keeps it in the memory.

While (depending upon the XSLT engine) XSLT prredominantly uses SAX. SAX if fast for through reading. But if the application requires data that cannot be retrieved in one pass multiple passes are required (I do not know the exact structure of your document). This multiple pass does consume longer time.

DOM takes a huge amount of memory - but nobody ever accused it to be very slow, sepecially if iterative reading is involved.

Thus, your result may be entirely correct. If I were you, I would also check the configuration and environment of the system.

If you require clarification, please contact me Ironluca@yahoo.com

Ironluca

Ironluca at 2007-6-29 8:58:11 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...