"Aron Stansvik" <[EMAIL PROTECTED]> wrote on 01/06/2006 15:19:06:
> On 6/1/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > > > > > Hi, > > > > I have a question about XPath and have been pointed in the direction of > > this mailing list. Hope this is the correct place. > > > > I have the following XPath: > > > > /base/group/[EMAIL PROTECTED]/instances/[EMAIL PROTECTED] > > > > and when used on my XML document it returns multiple items, e.g. > > > > /base[1]/group[1]/item[167]/instances[1]/instance[1] - result > > /base[1]/group[1]/item[195]/instances[1]/instance[1] - result > > /base[1]/group[1]/item[197]/instances[1]/instance[1] - result > > /base[1]/group[1]/item[202]/instances[1]/instance[1] - result > > /base[1]/group[1]/item[216]/instances[1]/instance[1] - result > > > > In this particular instance however, I only need to find one of the > > results, and it doesn't matter which one. > > For CPU efficiency I would like to find a way to do that. > > Does anyone know how I can achieve this, ideally by modifying my XPath, > > but if that is not possible, if there are parameters, or context set up > > that could be done within LibXML to restrict it to one result. > > You could use a predicate such as [position() = 1] to get the first > result. I don't know if this saves you anything performance-wise > though, one of the libxml2 hackers will have to answer that. > > > Best regards, > Aron Stansvik Hi Aron, I had played about with position(). Unless I am misunderstanding, The position refers to that within XML data structure and not an index into the XPath results. So position in the above instances are 167, 195, 197 etc... These values would change if the XML data changed or I changed the attributes within the XPath, I am hoping to find a generic XPath that could cope with that Thanks Alan ********************************************************************** 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
