2

My xml consist of words in few different language, Latin words etc. am able to parse these Latin characters and all except the fact that I am not able parse only "&"

This is what I am getting @gdb

Entity: line 223: parser error : > xmlParseEntityRef: no name Ull > always be mine 4 now & 4ever.Ull > always be mine 4 u r my treasure.Ull

Nimantha
  • 4,731
  • 5
  • 15
  • 38
Shishir.bobby
  • 10,696
  • 20
  • 67
  • 99

2 Answers2

6

The ampersand is treated as a special character because it is a special character. Ampersand is the start of an entity.

Ampersand ("&") needs to be written as & amp; or be contained in a CDATA section

See this link on how to escape XML strings in Objective-C

oluies
  • 16,976
  • 14
  • 66
  • 113
  • 1
    can u let me know about CDATA secion,l'll bit thanks for reply – Shishir.bobby Jun 02 '10 at 06:04
  • I am not sure if the link provided really solved MY issue with the parser. As far as I understand the code in the "how to escape" link, it returns a non-escaped string from an escaped, correct? So you would pass it something like 'B&ampB' and it would return 'B&B'? I ask, because in my case I have an XML file, which is created by the user manually. So I guess I have to replace those ampersands before parsing by &amp, which is the opposite of the code provided. Is there also anything like that I could do? – renesteg Feb 20 '12 at 17:42
  • See the [Google Toolbox](http://code.google.com/p/google-toolbox-for-mac/source/browse/trunk/Foundation/GTMNSString%2BXML.h) or look here http://stackoverflow.com/questions/803676/encode-nsstring-for-xml-html – oluies Feb 20 '12 at 21:47
0

I used this simple line of code in my case before parsing that xml:

cleaned = [original stringByReplacingOccurrencesOfString:@"&" withString:@"&"];

I did use [NSString stringByDecodingHTMLEntities]; Just before that since my server returns messages with tags.

avuthless
  • 986
  • 2
  • 12
  • 27