Why does GDataXMLDocument's nodesForXPath method fail?

271 views
Skip to first unread message

Zak

unread,
Jul 15, 2012, 3:17:36 AM7/15/12
to gdata-objec...@googlegroups.com
Here's my code:

GDataXMLDocument *doc = [[GDataXMLDocument alloc] initWithXMLString:myXMLString options:0 error:&xmlParseError];

NSInteger XPathCount = [[doc nodesForXPath:@"//entry/title" error:nil] count];

NSInteger elementsForNameCount = [[doc.rootElement elementsForName:@"title"] count];

NSLog(@"XPath count: %i"XPathCount );

NSLog(@"elementsForName count: %i"elementsForNameCount );

The result is the XPathCount returns 0 and elementsForNameCount returns 1 despite the fact that they should BOTH be 1, since they're pointing to the same thing. Just to make sure, I've doubled checked the name of the root element with doc.rootElement.name and it is indeed "entry". Why is nodesForXPath not detecting the element like it should?

Zak

unread,
Jul 15, 2012, 2:00:41 PM7/15/12
to gdata-objec...@googlegroups.com
There's something wrong with my XML string...I tried a different XML string and it worked fine. I'll have to investigate further.

Thomas Van Lenten

unread,
Jul 15, 2012, 2:23:01 PM7/15/12
to gdata-objec...@googlegroups.com
On Sun, Jul 15, 2012 at 2:00 PM, Zak <zakd...@gmail.com> wrote:
There's something wrong with my XML string...I tried a different XML string and it worked fine. I'll have to investigate further.

We might have to see the xml for sure, but don't you might be running into the xml namespaces also, you might need to qualify the name in the once case since you are searching the whole document and not basing it from a node what might provide some implicite namespaces for your search.

TVL
 


On Sunday, July 15, 2012 2:17:36 AM UTC-5, Zak wrote:
Here's my code:

GDataXMLDocument *doc = [[GDataXMLDocument alloc] initWithXMLString:myXMLString options:0 error:&xmlParseError];

NSInteger XPathCount = [[doc nodesForXPath:@"//entry/title" error:nil] count];

NSInteger elementsForNameCount = [[doc.rootElement elementsForName:@"title"] count];

NSLog(@"XPath count: %i"XPathCount );

NSLog(@"elementsForName count: %i"elementsForNameCount );

The result is the XPathCount returns 0 and elementsForNameCount returns 1 despite the fact that they should BOTH be 1, since they're pointing to the same thing. Just to make sure, I've doubled checked the name of the root element with doc.rootElement.name and it is indeed "entry". Why is nodesForXPath not detecting the element like it should?

--
You received this message because you are subscribed to the Google Groups "Google Data APIs Objective-C Client Library Discussion" group.
To view this discussion on the web visit https://groups.google.com/d/msg/gdata-objectivec-client/-/Wv7n_YqpDtIJ.

To post to this group, send email to gdata-objec...@googlegroups.com.
To unsubscribe from this group, send email to gdata-objectivec-...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/gdata-objectivec-client?hl=en.

Reply all
Reply to author
Forward
0 new messages