Hi, 

> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
> Sent: Thursday, June 01, 2006 5:18 PM
> To: Buchcik, Kasimier
> Cc: Aron Stansvik; Buchcik, Kasimier; [email protected]
> Subject: RE: [xml] XPath / LibXML question
> 
> Well, that certainly returns just the one result correctly...
> 
> I take it from your comments about it not being optimized that it will
> still find all results before returning the first, rather than just
> terminating at the first match?

Although it will return just one node, it will still try to apply the
predicate "[EMAIL PROTECTED]'2' and parent::instances/parent::[EMAIL 
PROTECTED]'1']]"
on all "instance" elements it finds in the document. So actually it will
run even slower than your original expression. I'll try to optimize
this.

But the expression I proposed (even if optimized) has the drawback that
it won't be as efficient as a plain chain of node-tests in the child
axis,
if you *don't* know if the document will be of the expected structure.
Hmm, don't know if I expressed this understandable enough; I think this
will become clearer if we assume that the given document has a document
element with the name "foo"; here my expression will still search the
whole tree for "instance" elements, while your expression would stop
already at the document element. So it all depends on how much you can
assume about the queried tree.

Another possibility would be to use a specialized Libxml2 function,
which
internally will try to return only the first match. Maybe someone else
knows if we have such a function already. But such a function won't be
much efficient, since the XPath mechanism of Libxml2 will still gather
and test all nodes up to "/base/group/[EMAIL PROTECTED]/instances", and then
it will have the chance to stop at the first match of
"[EMAIL PROTECTED]".

Regards,

Kasimier

> 
> Thanks
> 
> Alan
> 
> 
> "Buchcik, Kasimier" <[EMAIL PROTECTED]> wrote on 
> 01/06/2006 15:45:36:
> 
> > Hi,
> >
> > > -----Original Message-----
> > > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
> > > Behalf Of Buchcik, Kasimier
> > > Hi,
> > >
> > > As Aron already pointed out, the position() should be of
> > > help. You need to select the descendant-or-self or descendant
> > > axis.
> > > Your expression could look like this:
> > > "//[EMAIL PROTECTED]'2' and
> > parent::instances/parent::[EMAIL PROTECTED]'1']][1]"
> >
> > Whoops, sorry this should read:
> > "/descendant::[EMAIL PROTECTED]'2' and
> > parent::instances/parent::[EMAIL PROTECTED]'1']][1]"
> >
> > Regards,
> >
> > Kasimier
> 
> 
> **********************************************************************
> This email and any files transmitted with it are confidential and
> intended solely for the use of the individual or entity to whom they
> are addressed. If you have received this email in error please notify
> [EMAIL PROTECTED]
> 
> This footnote also confirms that this email message has been checked
> for all known viruses.
> 
> **********************************************************************
> Sony Computer Entertainment Europe
> 
> 
> 
_______________________________________________
xml mailing list, project page  http://xmlsoft.org/
[email protected]
http://mail.gnome.org/mailman/listinfo/xml

Reply via email to