PDA

View Full Version : SimpleXML + PHP + text formatting within the xml itself.


rlemon
11-23-2005, 09:39 PM
is it possible, using SimpleXML (php) to read it, to have html text formatting within a node?

example:

<node>
<child1>value</child1>
<child2>value with <b>html formatting</b></child2>
</node>

this doens't work for me... do i need to make replace strings for the text formatting? then like ?

gsnedders
11-23-2005, 10:20 PM
Any XML parser will see that as:
<node>
<child1>
value
</child1>
<child2>
value with
<b>
html formatting
</b>
</child2>
</node>

Your best bet is to escape the contents like <child2>value with &amp;lt;b&amp;gt;html formatting&amp;lt;/b&amp;gt;</child2>, then run html_entity_decode() or htmlspecialchars_decode() on each child.

KC-Luck
11-25-2005, 03:32 PM
or just wrap with <![CDATA[ ]]>

<node>
<child1>value</child1>
<child2><![CDATA[value with <b>html formatting</b>]]></child2>
</node>