Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to solve Ampersand (&) conversion issue in XML?

Tags:

xml

I am creating XML file using XMLDocument, but when XML node get '&' as data, it converting in "Ampersand(&)amp;" but i need actual value that is '&', Can anyone please tell me how can I achieve it?

Result:

like image 590
user2493287 Avatar asked Dec 02 '22 19:12

user2493287


2 Answers

A single & is illegal in an XML document (outside of CDATA sections; see @rsp's answer), so this is not possible. If there is a verbatim ampersand in your node data, it has to be encoded as &.

But it's also no problem because any XML reader will decode & as a literal & when parsing the XML file.

like image 158
Tim Pietzcker Avatar answered Dec 04 '22 07:12

Tim Pietzcker


If it is really necessary to have unescaped ampersands in your XML representation, you can use CDATA sections at the expense of the <![CDATA[ start and ]]> end around your character data.

like image 42
rsp Avatar answered Dec 04 '22 09:12

rsp