开发者

-[NSXMLNode nodesForXPath:error:] returns empty array while it should not

开发者 https://www.devze.com 2023-04-11 10:02 出处:网络
I am trying to parse an Atom feed. I have extended NSXMLNode with this method through a category: - (NSString *)stringValueForNodeAtXPath:(NSString *)XPath error:(NSError **)error {

I am trying to parse an Atom feed. I have extended NSXMLNode with this method through a category:

- (NSString *)stringValueForNodeAtXPath:(NSString *)XPath error:(NSError **)error {
  NSArray *nodes = [self nodesForXPath:XPath error:error];
  if ([nodes count] == 0) { return nil; }
  return [[nodes lastObject] stringValue];
}

This method returns the string value of a node when only one node is expected.

An Atom feed's entry looks like this:

<entry>
  <title开发者_开发知识库>A title</title>
  <id>Unique id</id>
</entry>

I have an NSXMLElement object like the one above. However, when trying to get either the title or the id of the entry, -[NSXMLNode nodesForXPath:error:] returns an empty array (and therefor my extension returns nil):

_uniqueId = [[XMLElement stringValueForNodeAtXPath:@"/entry/id" error:error] copy];

What could be the problem? Is my XPath query wrong? There is clearly an id in the entry, and entry is the root element.


Yes, NSLog-ing XMLElement confirms my last sentence.

0

精彩评论

暂无评论...
验证码 换一张
取 消