Re: Accessing attributes of XML (Christian Graus)
Re: Accessing attributes of XML (Christian Graus)
- Subject: Re: Accessing attributes of XML (Christian Graus)
- From: Richard Wolf <email@hidden>
- Date: Mon, 5 May 2008 19:55:13 -0500
On May 5, 2008, at 6:49 PM, email@hidden wrote:
I had to pick up the XPath stuff recently for a project I was working
on, and I've got to say that once you get yourself thinking in that
way, it's really very nice for inspecting XML files, giving you
great,
readable control for grabbing segments out of the document and then
inspecting or manipulating them.
Yes, XPath is very nice and very powerful, once you get the hang of
it.
I confess to having an XQuery book that i've never read, because
XPath has
always worked, and I've never worked on a project where anyone else
saw a
need for XQuery.
Christian,
I hate to beat a dead horse (and I'm totally going to shut up after
this post ... all glory to the moderators!), but what you're after can
be done using a single Cocoa method and XQuery:
NSArray *array = [node
objectsForXQuery:@"let $result := ./DiaIndex/Item return $result"
error:&error];
In return, you get an array of NSStrings which represent the element
text contained in the DiaIndex Items within the root of your document.
If you need to access attributes (rather than element text), you can
do that too, with a slight XPath amend. :)
I admit that learning XQuery/XPath is going to take a little bit of
time ... but if I can learn Visual Studio and .NET for a project (and
I have) you can totally learn XQuery. :) XQuery support in NSXMLNode
is one of the unsung coolnesses in Cocoa, IMHO. :)
And now I go back to lurking. :)
_______________________________________________
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