NSXMLParser and entity references
1 answer
I put together a very quick prototype app to test this. What you are describing is not the behavior I see:
XML file:
<? xml version = "1.0" encoding = "UTF-8"? >
<my_element> Left & Right </ my_element>
Implementation:
#import "XMLMeController.h"
@implementation XMLMeController
- (IBAction)parse:(id)sender
{
NSURL *url = [NSURL fileURLWithPath:@"/Users/robertwalker/Desktop/test.xml"];
NSXMLParser *parser = [[NSXMLParser alloc] initWithContentsOfURL:url];
[parser setDelegate:self];
[parser parse];
[parser release];
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
NSLog(@"Found: %@", string);
}
@end
Console output:
2008-11-11 20: 41: 47.805 XMLMe [10941: 10b] Found: Left
2008-11-11 20: 41: 47.807 XMLMe [10941: 10b] Found: &
2008-11-11 20: 41: 47.807 XMLMe [ 10941: 10b] Found: right
As you can see, the parser finds "left", then "&" and then "right" as three separate events that are sent to the delegate.
I can't tell from your post, but you need to make sure the corresponding object is used in the XML file "& amp;" not just the "&" character, which is of course not valid in XML files.
+5
source to share