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

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
srikanth saladiAsked:
Who is Participating?
 
RobOwner (Aidellio)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?
0
 
srikanth saladiAuthor 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
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.