Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

convert &lt to < xml document

Tags:

xml

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

like image 898
boom Avatar asked Mar 08 '10 05:03

boom


2 Answers

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.

like image 117
Lachlan Roche Avatar answered Oct 04 '22 13:10

Lachlan Roche


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.

like image 43
Amarghosh Avatar answered Oct 04 '22 14:10

Amarghosh