sash
sash

Reputation: 8715

Excessive inter-word spacing when parsing XML

I am parsing XML using NSXMLParser. Everything works good except one XML tag:

<place>USA , Boston</place>

when I parse this tag, the value is

USA               ,               Boston

Somehow spaces are added between words. Any ideas why it is happening and how can I fix it?

UPDATED The code I am using is straightforward. The string that I receive in parser:foundCharacters: delegate call is already with spaces. I am using:

[_currentString appendString:[string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]];

to remove spaces and new lines, but it is only for the beginning and the end of the string.

Upvotes: 0

Views: 66

Answers (2)

Jayaprada
Jayaprada

Reputation: 954

  • In FoundCharacters method we have to replace these special character.

string =[string stringByReplacingOccurrencesOfString:@"\t" withString:@""];

[_currentString appendString:string];

Upvotes: 1

Buntylm
Buntylm

Reputation: 7373

Will be good if you show you code of in short if you can edit the XML format than one solution will be you can add the tag value between CDATA like

<place><![CDATA[USA , Boston]]></place>

CDATA section is a section of element content that is marked for the parser to interpret as only character data

Upvotes: 0

Related Questions