October 20th, 2010, 03:22 AM
Handling NON-ASCII char in XML
I am new to XML just started yesterday.
I have some problem with non-ASCII char in XML.
when such char comes in text, XML error-out.
I Googled for the error and found that "C data" can handle such thing.
but "C data" is not helping any more.
Here I am pasting the XML content
Please look at this in free time and help the needy
<field name="title"><![CDATA[RE: which is the best Touchscreen Phone right now? ]]></field>
There's also a few new phones coming out in October that might be worth waiting for, the desire HD, g2, acer liquid metal and the Nokia n8 (worth a look if the price is right)
October 20th, 2010, 08:13 AM
Set an encoding for the file and XML, then make sure the contents are in that encoding. A CDATA won't help.
Alternatively, encode the characters with entities: U+0008 would be &&#35;8;.
October 20th, 2010, 08:40 AM
Thanks requinix for your time.
But I did'nt got you.
please modify the given XML ( in first Post) and please paste it in reply.
Originally Posted by requinix
October 20th, 2010, 09:18 PM
January 31st, 2011, 04:02 AM
Got the solution for Handling Ctrl char in XML
deletion_char = ''.join([chr(i) for i in range(32)])
char_table = ''.join([chr(i) for i in range(256)])
new_xml_string = string.translate(xml_string , char_table, deletion_char)
Its working fine now.
Thanks All ..