Skip navigation.
 
mlBasic XPath Question
FROM : Mac QA
DATE : Thu Apr 03 22:40:07 2008

Hi,

I am trying to use the nodesForXPath:error: API to search an XML
document and find particular nodes. For example, my document has
multiple entries for various hosts that look something like this:

<host name="intel-mini.local">
   <user name="a">
       <run command="/beep" arguments="5">
       </run>
   </user>
</host>

So I want to craft an XPath to search the document in order to find
this specific host node. Currently, I am crafting my XPath string like
so:

NSString *xPath = [NSString
stringWithFormat:@"//host[@name=\"%@\"]",newHostname];

And I have also tried:

NSString *xPath = [NSString
stringWithFormat:@"//host[attribute::name=\"%@\"]",newHostname];

However neither work for finding this particular host node. Yet, when
I use the following XPath I can get an array of all the host nodes.

NSString *xPath = [NSString stringWithFormat:@"//host"];

Does the nodesForXPath:error: API in Cocoa just not support the
features of XPath for matching nodes with specific attribute values?
Or am I just doing something totally wrong? Any suggestions or
pointers to examples would be greatly appreciated. Thanks!

Related mailsAuthorDate
mlBasic XPath Question Mac QA Apr 3, 22:40
mlRe: Basic XPath Question Jens Alfke Apr 3, 22:51