• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Accessing attributes of XML (Christian Graus)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Accessing attributes of XML (Christian Graus)
      • From: "Christian Graus" <email@hidden>
  • Prev by Date: Re: I Never get 'self' in Obj-C
  • Next by Date: Re: Accessing attributes of XML (Christian Graus)
  • Previous by thread: Re: Cached text output is flippin' flipped! [SOLVED]
  • Next by thread: Re: Accessing attributes of XML (Christian Graus)
  • Index(es):
    • Date
    • Thread