how to add data to xml node value while parsing xml in php

srikanth saladi
srikanth saladi used Ask the Experts™
on
Hi,

I need to add cdata to a node in an xml while parsing xml. I was unable to parse the content from that node. i had added CDATA by editing the xml, it worked fine and able to parse. But i need to add CDATA on the fly while parsing the xml and need to read that value as string.

Please find the xml node that needs to be added with cdata in the attached xml.

<Descriptionlongue>
<p><strong>Froid Ventilé Multi Air Flow</strong><br/><strong>Classe Energétique A+</strong><br/><strong>Affichage LED</strong><br/><br/></p> <table class="fridge-mini-spec" cellspacing="0" cellpadding="0" border="0"><tbody><tr><td>Volume total net <span>(L)</span></td> <td>432</td> </tr><tr><td>Volume utile du réfrigérateur <span>(L)</span></td> <td>290 </td> </tr><tr><td>Volume utile du congélateur <span>(L)</span></td> <td>142</td> </tr><tr><td>Classe énergétique</td> <td>A+</td> </tr><tr><td>Largeur * Profondeur * Hauteur (cm)</td> <td>79*70*181</td> </tr><tr><td>Finition</td> <td>Métal brillant</td> </tr></tbody></table>
</Descriptionlongue>
RQ562N4AC1-fr-1-.xml
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Owner (Aidellio)
Most Valuable Expert 2015
Commented:
Unfortunately it's one of those chicken and egg problems... you can't add the node until you've parsed the code and you can't parse the code if it's not well formed.

What I suggest is reading in the xml file as a string, make the changes and then parse?

Author

Commented:
Hi ,

Yes, it seems not possible to add CDATA while parsing. will go with suggested solution  of converting string and then applying changes and parsing

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial