Help with nodesForXPath
Help with nodesForXPath
- Subject: Help with nodesForXPath
- From: "Huibert Aalbers" <email@hidden>
- Date: Tue, 2 May 2006 01:55:36 -0500
Hi,
I am trying to parse an XML document (an RSS feed), which should be
easy using NSXMLDocument. My code is quite straightforward and looks
very similar to what I have seen in Apple's sample code.
contents = [NSString stringWithContentsOfURL:theURL];
xmlDoc = [[[NSXMLDocument alloc] initWithXMLString:contents
options:(NSXMLNodePreserveWhitespace|NSXMLNodePreserveCDATA)
error:&err] autorelease];
if (!err) {
if (xmlDoc !=nil) {
HTMLMutableString = [NSMutableString stringWithCapacity:1000];
[HTMLMutableString appendString:[NSString
stringWithContentsOfFile:[[NSString stringWithString:[[NSBundle
bundleForClass:[self class]] resourcePath]]
stringByAppendingString:@"/Test.html"]]];
if ([[[xmlDoc rootElement] name] isEqualToString:@"rss"] ) {
if ([[[[xmlDoc rootElement] attributeForName:@"version"]
stringValue] isEqualToString:@"0.91"]) {
[HTMLMutableString replaceOccurrencesOfString:@"$1"
withString:@"RSS 0.91" options:0 range:NSMakeRange(0,
[HTMLMutableString length])];
nodes = [[xmlDoc rootElement] nodesForXPath:@"//item"
error:&err]; // This line doesn't produce results
if (!err) {
for (index = 0; index < [nodes count]; index++) {
NSLog(@"Result %d:", index);
NSLog(@"Result %d: %@", index, [nodes objectAtIndex:0]);
}
}
else NSLog(@"Error: %@",err);
...
However, I do not get any result, no matter what XPath expression I
use. I am so desperate that I have even tried illegal XPath
expressions. I was very surprised to see that even in that case no
error was returned by the method.
Does anyone have a clue as what may be going on? Thanks in advance,
Huibert
--
Visit my home page at http://www.huibert-aalbers.com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden