PHP Class LSS\Array2XML

It throws exception if the tag name or attribute name has illegal chars. Author : Lalit Patel Website: http://www.lalit.org/lab/convert-php-array-to-xml-with-attributes License: Apache License 2.0 http://www.apache.org/licenses/LICENSE-2.0 Version: 0.1 (10 July 2011) Version: 0.2 (16 August 2011) - replaced htmlentities() with htmlspecialchars() (Thanks to Liel Dulev) - fixed a edge case where root node has a false/null/0 value. (Thanks to Liel Dulev) Version: 0.3 (22 August 2011) - fixed tag sanitize regex which didn't allow tagnames with single character. Version: 0.4 (18 September 2011) - Added support for CDATA section using @cdata instead of @value. Version: 0.5 (07 December 2011) - Changed logic to check numeric array indices not starting from 0. Version: 0.6 (04 March 2012) - Code now doesn't @cdata to be placed in an empty array Version: 0.7 (24 March 2012) - Reverted to version 0.5 Version: 0.8 (02 May 2012) - Removed htmlspecialchars() before adding to text node or attributes. Usage: $xml = Array2XML::createXML('root_node_name', $php_array); echo $xml->saveXML();
Exibir arquivo Open project: openlss/lib-array2xml Class Usage Examples

Public Methods

Method Description
createXML ( string $node_name, array $arr = [] ) : DomDocument Convert an Array to XML
init ( $version = '1.0', $encoding = 'UTF-8', $format_output = true ) Initialize the root XML node [optional]

Private Methods

Method Description
bool2str ( $v ) * Get string representation of boolean value
convert ( string $node_name, array $arr = [] ) : DOMNode Convert an Array to XML.
getXMLRoot ( ) * Get the root XML node, if there isn't one, create it.
isValidTagName ( $tag ) * Check if the tag name or attribute name contains illegal characters Ref: http://www.w3.org/TR/xml/#sec-common-syn

Method Details

createXML() public static method

Convert an Array to XML
public static createXML ( string $node_name, array $arr = [] ) : DomDocument
$node_name string - name of the root node to be converted
$arr array - aray to be converterd
return DomDocument

init() public static method

Initialize the root XML node [optional]
public static init ( $version = '1.0', $encoding = 'UTF-8', $format_output = true )
$version
$encoding
$format_output