• 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: nodesForXPath does not seem to work in Address Book Plug-Ins
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: nodesForXPath does not seem to work in Address Book Plug-Ins


  • Subject: Re: nodesForXPath does not seem to work in Address Book Plug-Ins
  • From: Sam Stigler <email@hidden>
  • Date: Thu, 7 Jun 2007 16:37:29 +1000

Hi,

I've been using XPath and XQuery a lot recently in my own app, so I'll try to give you some advice. First off, I notice that you're using '"." as your XPath. That's likely not to return anything -- all of my successful -nodesForXPath queries, at least, have started with "/", and left the "." out entirely. In fact, the W3Schools' XPath tutorial notes that if you want the root node, you should use "/" -- "." signifies the current node (http://www.w3schools.com/xpath/ xpath_syntax.asp).

The "." would, however, work in an XQuery expression, asking for the root node of the document: NSArray *xQueryResults = [document objectsForXQuery:@"." error:&err] . (I checked this by trying it in the XMLBrowser sample project; see below.)

One program that I've found to be particularly useful at debugging XPath-related troubles is AquaPath (search for it on VersionTracker). While it is slow for parsing large documents, it is invaluable for the insight it gives you into what exactly will be returned for a given XPath. Two other strategies I've found helpful:
-Use trial and error in the Debugger: Set a breakpoint at your - nodesForXPath call, and then step over that. If the array contains 0 objects, modify the XPath (maybe using AquaPath as an aid), press "Fix", drag the red arrow back up to the -nodesForXPath call, and repeat.
-If you're willing to look into -objectsForXQuery (which it turns out is actually more powerful), take a look at the XMLBrowser example (/Developer/Examples/Foundation/XMLBrowser). If you build and run it, it is a program just like AquaPath, but faster and geared towards XQuery instead of XPath.


However, having said all this, if all you want to do is get the root node of the document, it's probably much easier for you to just use [document rootElement] .

I hope this helps,
Sam


On Jun 7, 2007, at 3:56 PM, Gernot Poetsch wrote:

Hi!

Thanks for the replies! Yeah, I checked for the error, and it is
nil... I left the error check out of the example code to keep it at
the smallest possible size. I think I'll file a bug report and look
for alternatives to using XPath...

cheers,
Gernot.

On 6/7/07, Tomas Franzén <email@hidden> wrote:
On 6 jun 2007, at 21.07, Gernot Poetsch wrote:
> I've got a strange problem developing an Address Book Plug-in. In the
> plugin I parse XML-Data, but somehow -[NSXMLDocument
> nodesForXPath:error:] does always return an empty array.
> NSArray *xPathResults = [document nodesForXPath:@"." error:NULL];


Hi,

Have you tried using the error argument to see if there's actually an
error reported?

Tomas Franzén
Lighthead Software
http://www.lightheadsw.com/


_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:
40mac.com


This email sent to email@hidden

_______________________________________________

Cocoa-dev mailing list (email@hidden)

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


References: 
 >nodesForXPath does not seem to work in Address Book Plug-Ins (From: "Gernot Poetsch" <email@hidden>)
 >Re: nodesForXPath does not seem to work in Address Book Plug-Ins (From: Tomas Franzén <email@hidden>)
 >Re: nodesForXPath does not seem to work in Address Book Plug-Ins (From: "Gernot Poetsch" <email@hidden>)

  • Prev by Date: StrokeColor in NSTextView
  • Next by Date: Re: Value With Pattern binding not working as expected
  • Previous by thread: Re: nodesForXPath does not seem to work in Address Book Plug-Ins
  • Next by thread: NSTextFieldCell and -stopTracking::
  • Index(es):
    • Date
    • Thread