note 86085 added to function.simplexml-element-addChild

[email protected]
Newsgroups php.notes
Message-ID <[email protected]>
I found this easy way to create a CDATA section as child value:

I extend the class SimpleXMLElement:

class SimpleXMLExtended extends SimpleXMLElement
{
  public function addCData($cdata_text)
  {
    $node= dom_import_simplexml($this);
    $no = $node->ownerDocument;
    $node->appendChild($no->createCDATASection($cdata_text));
  }
}

Then in the main code:
$xml = new SimpleXMLExtended('<?xml version = "1.0" encoding = "UTF-8"?><root></root>');
$mynode = $xml->addChild("myname");
$mynode->addCData("my name contains everything I want &%<>");
echo $xml->asXml();
----
Server IP: 69.147.83.197
Probable Submitter: 89.96.52.107
----
Manual Page -- http://www.php.net/manual/en/function.simplexml-element-addChild.php
Edit        -- https://master.php.net/note/edit/86085
Del: integrated  -- https://master.php.net/note/delete/86085/integrated
Del: useless     -- https://master.php.net/note/delete/86085/useless
Del: bad code    -- https://master.php.net/note/delete/86085/bad+code
Del: spam        -- https://master.php.net/note/delete/86085/spam
Del: non-english -- https://master.php.net/note/delete/86085/non-english
Del: in docs     -- https://master.php.net/note/delete/86085/in+docs
Del: other reasons-- https://master.php.net/note/delete/86085
Reject      -- https://master.php.net/note/reject/86085
Search      -- https://master.php.net/manage/user-notes.php
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.