Note that there are some explanatory texts on larger screens.

plurals
  1. PONSXML Parsing Ampersand Character Causes Shut Down
    text
    copied!<p>I am parsing a simple XML file, however sometimes there are tags that contain ampersands (&amp;) in the node. I've done some research <a href="https://stackoverflow.com/questions/7838708/how-to-parse-strings-containing-ampersands-with-nsxmlparser">here</a> and <a href="https://stackoverflow.com/questions/7291534/nsxmlparser-problem-with-ampersand-character">here</a> but the problem is persisting. The problem is that the parser simply stops when it encounters the offending XML element. The XML looks like this: </p> <pre><code>&lt;video&gt; &lt;video_id&gt;42&lt;/video_id&gt; &lt;video_header&gt;Six &amp; Eight&lt;/video_header&gt; &lt;video_subheader&gt;So Long&lt;/video_subheader&gt; &lt;/video&gt; </code></pre> <p>The parser is updating an object, called <code>DisStep</code>, that has a <code>parsedVideoArray</code> attribute. The attribute is just an array of <code>Parsed_Video</code> objects. So the problem would be that when the the parser gets to <code>foundCharacters</code> for the element <code>video_header</code> it will not continue to <code>didEndElement</code>. In fact, an <code>NSLog</code> in the foundCharacters method of <code>currentNodeContent</code> is just <code>"Six "</code>.</p> <p>And here is the code for the parser. All it does is look for videos and gather info about them.</p> <pre><code>-(void) parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict { if ([elementName isEqualToString:@"video"]) { videoBeingParsed = [[Parsed_Video alloc] init]; } } -(void) parser:(NSXMLParser *)parser foundCharacters:(NSString *)string { string = [string stringByReplacingOccurrencesOfString:@"&amp;" withString:@"&amp;amp;"]; currentNodeContent = (NSMutableString *) string; } - (void) parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName { if ([elementName isEqualToString:@"video_id"]) { videoBeingParsed.Video_ID = currentNodeContent; currentNodeContent = nil; } else if ([elementName isEqualToString:@"video_header"]) { videoBeingParsed.Video_Header = currentNodeContent; currentNodeContent = nil; } else if ([elementName isEqualToString:@"video_subheader"]) { videoBeingParsed.Video_SubHeader = currentNodeContent; currentNodeContent = nil; } else if ([elementName isEqualToString:@"video"]) { [DisStep.parsedVideoArray addObject:videoBeingParsed]; currentNodeContent = nil; videoBeingParsed = nil; } } @end </code></pre> <p>I tried the <code>stringByReplacingOccurrencesOfString: withString:</code> but the parser still stops working. Is there a way around this other than changing the XML?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload