XPath: efficiency in xpath expressions

Discussion in 'XML' started by Tjerk Wolterink, Nov 13, 2004.

  1. I'm wondering what is faster in a big document
    something like:

    //element

    or this absolute path:

    /parent/parent2/parent3/element

    ?

    What is more efficient?
    I came to this question when reading this:
    http://dom4j.org/benchmarks/xpath/index.html
    Especially this sentence:

    The syntax of Xpath statements must be chosen carefully. Contrary to
    some belief, and of the topology of our XML format, using /*/* or // was
    most efficient compared to the absolute path /ItemResultSet/Item
    Tjerk Wolterink, Nov 13, 2004
    #1
    1. Advertising

  2. In article <41961c9e$0$45968$>,
    Tjerk Wolterink <> wrote:

    >I'm wondering what is faster in a big document
    >something like:
    >
    >//element
    >
    >or this absolute path:
    >
    >/parent/parent2/parent3/element


    It depends on the implementation strategy, but in a straightforward
    implementation, //element will have to examine every element in the
    document, while /parent/parent2/parent3/element will ignore the
    subtrees under, for example, /parent/other and /parent/parent2/other.

    In the (fairly unusual) case where there aren't any such irrelevant
    subtrees, the cost of checking the names of the parents will make
    //element faster.

    -- Richard
    Richard Tobin, Nov 13, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jay Douglas
    Replies:
    0
    Views:
    598
    Jay Douglas
    Aug 15, 2003
  2. Thor W Hammer
    Replies:
    0
    Views:
    1,757
    Thor W Hammer
    Mar 14, 2006
  3. Neil Zanella

    mozilla and XPath Expressions

    Neil Zanella, Dec 9, 2003, in forum: XML
    Replies:
    2
    Views:
    725
    Neil Zanella
    Dec 14, 2003
  4. Colin Toal
    Replies:
    3
    Views:
    819
    Colin Toal
    Jan 23, 2004
  5. Noman Shapiro
    Replies:
    0
    Views:
    232
    Noman Shapiro
    Jul 17, 2013
Loading...

Share This Page