Note that there are some explanatory texts on larger screens.

plurals
  1. POInaccurate xml parsing due to line breaks in the content
    primarykey
    data
    text
    <p>I am trying to parse XML using NSXMLParser but since some of the xml that I have contains line breaks () I am getting inaccurate parsing. For example "A genuine leader is not a&lt;br&gt; searcher for consensus&lt;br&gt;but, a molder of consensus" gets parsed as "a molder of consensus" Not only does the <br> tags mess it up but also the comma after but seems to mess it up, guessing its because of directly next to the br tag without a space. Anyone have experience on how to fix this? A lot of people hon Stackoverflow seem to have the same issue but I haven't been able to find a solution for iOS. </p> <p>In the xml the br tags prints out like this:</p> <pre><code>&amp;lt;br&amp;gt; </code></pre> <p>This is the xml I am parsing</p> <pre><code>&lt;entry&gt; &lt;title&gt;Quote&lt;/title&gt; &lt;content&gt;A genuine leader is not a&amp;lt;br&amp;gt; searcher for consensus&amp;lt;br&amp;gt; but, a molder of consensus&lt;/content&gt; &lt;/entry&gt; </code></pre> <p>This is my xml parsing code</p> <pre><code>- (void) parser:(NSXMLParser *)parser didStartElement:(NSString *)elementname namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict { if ([elementname isEqualToString:@"entry"]) { currentQuote = [[SQuote alloc] init]; } } - (void) parser:(NSXMLParser *)parser didEndElement:(NSString *)elementname namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName { if ([elementname isEqualToString:@"content"]){ currentQuote.content = currentNodeContent; } if ([elementname isEqualToString:@"entry"]) { [self.popularEntries addObject:currentQuote]; currentQuote = nil; currentNodeContent = nil; } } </code></pre> <p><strong>EDIT:</strong></p> <p>I tried changing my charactersFound code to the following :</p> <pre><code>- (void) parser:(NSXMLParser *)parser foundCharacters:(NSString *)string { if (currentNodeContent == nil) currentNodeContent = [[NSMutableString alloc] initWithCapacity: 20]; [currentNodeContent appendString: [string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]]; } </code></pre> <p>But I am still getting an error that says "Attempt to mutate immutable object with appendString:" even though currentNodeContent is of type NSMutableString</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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