CDATA Problem

Discussion in 'PHP' started by shiva_rnm, Sep 18, 2008.

  1. #1
    Hi

    I'm using PHP5's simpleXML object. I load in an XML file and overwrite an element containing CDATA tags, but when I do. the "<" and ">" characters get decoded to &lt; and &gt;

    My code looks like this:

    $xml = simplexml_load_file('sections.xml');
    $xml->section[0]->body = "<![CDATA[".$bodytext."]]>";
    $xml->asXML('sections.xml');

    but the updated xml node appears like:
    <body>&lt;![CDATA[Here is the body text at 2357]]&gt;</body>

    So how do you include "<" and ">" characters when writing to an xml file with simpleXML?

    I'm having encoding format as encoding="UTF-8".
     
    shiva_rnm, Sep 18, 2008 IP
  2. siaosiaokia

    siaosiaokia Guest

    Messages:
    24
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    siaosiaokia, Sep 19, 2008 IP