Re: Cocoa-dev Digest, Vol 5, Issue 730
Re: Cocoa-dev Digest, Vol 5, Issue 730
- Subject: Re: Cocoa-dev Digest, Vol 5, Issue 730
- From: Richard Wolf <email@hidden>
- Date: Mon, 5 May 2008 13:33:51 -0500
Christian,
It's just like I posted to Mr. Gecko. XQuery is your friend. XPath
returns nodes, XQuery allows you to return values.
An XQuery to return the text inside your DiaIndex/Items is simple ...
it would look like this:
let $result := ./DiaIndex/Item return $result
Notice that XQuery uses XPath ... XQuery 1.0 is inseparable from XPath
2.0.
In Cocoa, you can ask an NXXMLNode (including your root node) to
execute an XQuery and return the result as an NSArray of Cocoa things
(what's returned depends on what data types XQuery sees in your
XML ... it's usually NSStrings). It is simple to change your code to
execute the XQuery.
NSXMLDocument *doc = [[NSXMLDocument alloc]
initWithContentsOfURL:xmlURL options:0 error:&error];
NSXMLNode *node = [doc rootElement];
NSArray *array = [node
objectsForXQuery:@"let $result := ./DiaIndex/Item return $result"
error:&error];
Guess what "array" has? A set of NSStrings that are the contents of
your /DiaIndex/Items. :)
It's just that simple. :)
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden