Welcome to the Cookbook

loading...

7.12.2 elem

The elem method allows you to build an XML node string with attributes and internal content, as well.

string elem (string $name, $attrib = array(), mixed $content = null, $endTag = true)

echo $xml->elem('count', array('namespace' => 'myNameSpace'), 'content');
// generates: <myNameSpace:count>content</count>
  1. echo $xml->elem('count', array('namespace' => 'myNameSpace'), 'content');
  2. // generates: <myNameSpace:count>content</count>

If you want to wrap your text node with CDATA, the third argument should be an array containing two keys: 'cdata' and 'value'

echo $xml->elem('count', null, array('cdata'=>true,'value'=>'content'));
// generates: <count><![CDATA[content]]></count>
  1. echo $xml->elem('count', null, array('cdata'=>true,'value'=>'content'));
  2. // generates: <count><![CDATA[content]]></count>