Nick Nick - 3 months ago 10
Objective-C Question

Can NSXMLParser access strings or comments in XML files?

I have an XML file that I have successfully parsed and I know that NSXMLParser uses the functions listed below but is it possible to search by strings instead of element tags? I want to find the string that is commented out at the bottom of my XML file. Is there anyway to access that commented out string with NSXMLParser?

XML CODE

<audioTracks>0</audioTracks>
<!--7934fad5a3a -->


PARSING CODE

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict {
if ([elementName isEqualToString:@"audioTracks"]) {
NSLog(@"Element Name: --> %@", elementName);
}
}

- (void) parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
NSLog(@"foundCharacters --> %@", string);
}

- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
if ([elementName isEqualToString:@"audioTracks"]) {
NSLog(@"Element Name: --> %@", elementName);
}
}

Answer

You need to implement the following delegate method on NSXMLParserDelegate to handle comments in the XML file being processed:

- (void)parser:(NSXMLParser *)parser foundComment:(NSString *)comment

Comments