Re: [xml] Simple Element+Attribute Lookup with XPath - performance ?



On Wed, Jul 16, 2008 at 07:40:21AM +0200, Martin Trappel wrote:
<ROOT>
  <FOO Name="a">
    <BAR Id="2"/>
    <BAR Id="1"/>
    <BAR Id="4"/>
    ...
    <BAR Id="2345"/>
  </FOO>
  <FOO Name="b">
    ...
  </FOO>
  ...
</ROOT>
[...]
Use the xpath search expression 'BAR[ id="4"]' and use the returned nodeset.

While I don't know why this expression is slow, you might want to try
the "id()" or keyref mechanisms. They are very fast because of an
additional index structure. However, this only works properly if your
@id values are unique in the whole document, i.e. among all <FOO>
elements.

You could also try to use this XPath expression:

    *[ id="4"]

It might be faster if all sub elements of <FOO> are <BAR>s.


 for(int i=0, e=xpo->nodesetval->nodeNr; i<e; ++i) {
   xmlChar* p_val = xmlGetProp(xpo->nodesetval->nodeTab[i], "id");
   if(p_val && 0==strcmp("4", p_val)) {

Please note that in C the order of execution of

    p_val

and

    0==strcmp("4", p_val)

is not specified! Some compilers could generate code that
checks the second condition first, which could lead to a
segmentation fault or similar.


Greets,

    Volker

-- 
Volker Grabsch
---<<(())>>---
Administrator
NotJustHosting GbR



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]