tags:

views:

378

answers:

4

Hi,

I'm having a problem with SimpleXML. When I'm using the children() method to get the contents of an XML element, with elements that contain HTML, it will parse the HTML contents as XML. How would I make it so that it won't parse HTML?

+2  A: 

did you try to use CDATA ?

<xml>
    <node>
        <![CDATA[
        <div>
            <img src="..." />
        </div>
        ]]>
    </node>
</xml>
Natrium
+1  A: 

The example you posted is valid XML, but the <div> and <img>-tags are part of the XML document.

Basically, you have to use CDATA (see natriums answer), or escape the HTML entities in the XML.

gnud
A: 

Hi!

I tried CDATA, but this doens't work. Could you just give me an real example of use, to see if I am right with my one?

Thank you in advance. b1

b1
A: 

CDATA worked with me! =D

<?xml version="1.0" encoding="UTF-8"?>
<destaques>
    <destaque imagem="cartoes.jpg">
        <![CDATA[
            Text with <em>some</em> HTML.

        ]]>
    </destaque>
    <destaque imagem="banner2.jpg" />
    <destaque imagem="delivery.jpg" />
</destaques>
glaucomorais