0

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?

3 Answers 3

3

did you try to use CDATA ?

<xml>
    <node>
        <![CDATA[
        <div>
            <img src="..." />
        </div>
        ]]>
    </node>
</xml>
Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

0

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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.