开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜