• 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
Help with nodesForXPath
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Prev by Date: Implementing an Inspector using Bindings (across multiple NSArrayControllers)
  • Next by Date: Re: NSButton image binding
  • Previous by thread: Implementing an Inspector using Bindings (across multiple NSArrayControllers)
  • Next by thread: Bonjour and sending data
  • Index(es):
    • Date
    • Thread