XML handling for CakePHP.
The methods in these classes enable the datasources that use XML to work.
_createChild( array $data )
Helper to _fromArray(). It will create childs of arrays
$data _fromArray( DOMDocument $dom , DOMElement $node , array $data , string $format )
Recursive method to create childs from array
$dom $node $data $format XmlException_loadXml( string $input , array $options )
Parse the input data and create either a SimpleXmlElement object or a DOMDocument.
$input $options XmlException_toArray( SimpleXMLElement $xml , array $parentData , string $ns , array $namespaces )
Recursive method to toArray
$xml $parentData $ns $namespaces build( string|array $input , array $options array() )
Initialize SimpleXMLElement or DOMDocument from a given XML string, file path, URL or array.
Building XML from a string:
$xml = Xml::build('<example>text</example>');
Building XML from string (output DOMDocument):
$xml = Xml::build('<example>text</example>', array('return' => 'domdocument'));
Building XML from a file path:
$xml = Xml::build('/path/to/an/xml/file.xml');
Building from a remote URL:
$xml = Xml::build('http://example.com/example.xml');
Building from an array:
$value = array(
'tags' => array(
'tag' => array(
array(
'id' => '1',
'name' => 'defect'
),
array(
'id' => '2',
'name' => 'enhancement'
)
)
)
);
$xml = Xml::build($value); When building XML from an array ensure that there is only one top level element.
return Can be 'simplexml' to return object of SimpleXMLElement or 'domdocument' to return DOMDocument.loadEntities Defaults to false. Set to true to enable loading of <!ENTITY definitions. This is disabled by default for security reasons.readFile Set to false to disable file reading. This is important to disable when putting user data into Xml::build(). If enabled local & remote files will be read if they exist. Defaults to true for backwards compatibility reasons.options from Xml::fromArray.$input $options optional array() XmlExceptionfromArray( array $input , array $options array() )
Transform an array into a SimpleXMLElement
format If create childs ('tags') or attributes ('attributes').pretty Returns formatted Xml when set to true. Defaults to false
version Version of XML document. Default is 1.0.encoding Encoding of XML document. If null remove from XML header. Default is the some of application.return If return object of SimpleXMLElement ('simplexml') or DOMDocument ('domdocument'). Default is SimpleXMLElement.Using the following data:
$value = array(
'root' => array(
'tag' => array(
'id' => 1,
'value' => 'defect',
'@' => 'description'
)
)
); Calling Xml::fromArray($value, 'tags'); Will generate:
<root><tag><id>1</id><value>defect</value>description</tag></root>
And calling Xml::fromArray($value, 'attributes'); Will generate:
<root><tag id="1" value="defect">description</tag></root>
$input $options optional array() XmlExceptiontoArray( SimpleXMLElement|DOMDocument|DOMNode $obj )
Returns this XML structure as an array.
$obj XmlException
© 2005–2016 The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
https://api.cakephp.org/2.9/class-Xml.html