tags:

views:

542

answers:

4

Hi,

I have read an XML file and converted into NSXMLDocument object. But, due to the presence of "<" in the string content of a node, it has been converted into "&lt". So, when i write it as xml document to a file, it has the character "&lt" in it.

How can i write to the file as ordinary XML file in which "&lt" will be replaced by "<".

Thanks and Regards, Lenin

A: 

The < in text nodes of an xml should be represented as &lt;.

If you replace it using s/&lt;/</g before writing it to the xml file, it will lead to parsing error when you read from that file.

Amarghosh
A: 

You can use following function for doing the vice versa operation

htmlspecialchars and

htmlentities()

pavun_cool
Thanks for this. will check it out.
iSight
Hi, my code is in cocoa. Can you give alternative methods to convert it in cocoa rather than htmlspecialchars and htmlentities()
iSight
@Lenin : Sorry , I am not aware of cocao
pavun_cool
A: 
Mike Cialowicz
A: 

When the < character appears in a text node, it will be serialized as &lt; when you write your xml to a file.

When you later read that file with an xml parser, the text node will contain the original < character.

You also have the option of CDATA encoding the text node. In this case the serialized character is < inside a CDATA block. Many XML APIs will not retain any difference between CDATA and text nodes. CDATA should be thought of as an escaping mechanism to make editing easy for human authors.

Lachlan Roche