Forum Stats

  • 3,875,873 Users
  • 2,266,977 Discussions
  • 7,912,362 Comments

Discussions

XPATH vs DOM tests acomplishied

843834
843834 Member Posts: 49,972
edited Jul 29, 2001 4:08AM in Java Technology & XML
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


Comments

  • 843834
    843834 Member Posts: 49,972
    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 [email protected]

    Ironluca
This discussion has been closed.