Plist contains the "&" character - iphone

I'm having a .plist file which has some values with the "&" sign, for example "M&I". When I save the file to the document folder and load it from there, I'm getting an empty dictionary. Any idea to how to fix this issue?

If you are directly modifying the XML file, you have to escape certain characters - & should be escaped using the XML entity &. If you use the editors, this should be done automatically for you.
If you use CDATA sections instead, you don't have to escape the characters.

If you insert the values when open plist file as property list it would do it automatically.

Related

XML Parsing issue with special characters

I am trying to display “Administrative File & Express” but it is displaying as "Express". So I am unable to show anything that is before the “&”.
You need to escape chars like '&' in XML Parsing. See following link...
http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references
What characters do I need to escape in XML documents?
Now check XML you are receiving. if you are not receiving chars with escape sequence then you need to handle it in your code.....
Write here if you need further details.....

writing subscripts in .plist files

I am trying to represent the number 2 as a subscript in a property list file. I tried using<sub>2</sub>, but it doesn't seem to work. Can anyone help me with this? and will it be stored correctly in a string after I store it there?
A plist file is XML that follows a certain schema. <sub> is not a valid tag in that schema. If you want to put that kind of stuff in the PList, you have to put in into CDATA:
<![CDATA[<sub>2</sub>]]>
A plist file is typically a UTF-8 encoded XML file. You should be able to use the Unicode subscript characters as it is. To copy a non-ASCII char, you can use the Keyboard & Character Viewer (on Lion: System Preferences > Language & Text > Input Sources > Select the Keyboard & Character Viewer as an input source).

Formatting string from plist dictionary with new lines

I have some strings stored in a plist dictionary, the values of which i would like to display in a textview.
the strings are stored with \n for new lines, however when i pull out the string, it shows \n characters as literals instead of converting them to new lines
Here is the code to pull out the value
self.directions.text = [NSString stringWithFormat:#"%#",[self.exerciseDetail objectForKey:DIRECTIONS_KEY]];
How can i fix it?
Stored strings: some text \n some more text \n some more text
The problem here is that the plist file is storing the string with "\" and "n" characters, rather than a single newline character. The best fix (in my opinion) would be to fix the plist file to have the correct characters. If you are using the plist editor built into Xcode, then hitting the Enter key moves you to the next field. To get around this, hold the Option key while typing Enter and a newline will be inserted.

escape character & stopping parsing

I am trying to parse some data using nsxmlparser, whenever there is a &(ampersand) present in the text being received it just stops reading the parsed data. How can I read & normally, similar to other normal characters.
Thanks
Pankaj
A lone ampersand in an XML document is not valid except in a CDATA section. You can either have your XML provider provide valid XML by either:
Using the & character entity where you want ampersands.
Putting text containing ampersands into a CDATA section.
Could not find the solution so i had to replace the & with some characters in backend and then again replace it in iphone while using it

Emoji iCons are not displaying correctly when read from plist

I am trying to read some text from a plist file and display it to the users in alert box.
When I build the string using this code, everything works (users sees Hello with a smily icon):
NSString *hello = #"Hello \ue415";
but when I get the string from plist, using this code, uses sees "Hello \ue415":
NString *hello = (NSString *)[pageLiteratureDic objectForKey:litratureKey];
Do I have to encode string differently? Any help or pointers will be much appreciated... everyone love emojis ;)
You shouldn't literally type "\ue415" as text into the plist file. \u.... is an escape sequence in the syntax of strings and characters in the C language. The string itself does not contain backslash and "u" and whatever, it contains just 1 character, the Unicode character at the codepoint 0xe415. If you want to save that in a plist, you have to manually type that one Unicode character in there yourself, making sure to use whatever encoding that is required of a plist (maybe utf-8 or utf-16, not sure). Alternately, you can write a program that creates a plist from that string, and then copy and paste whatever is in that plist file over to your file.
In the plist, instead of "Hello \ue415" try using the smily face character explicitly as in "Hello :)". Just cut and paste the smily character over the unicode code. The reading of the plist is probably escaping the backslash and stopping the interpretation as a unicode character.