public static function array_to_xml(XMLElement $parent, array $data, $validate = false)
    {
        foreach ($data as $element_name => $value) {
            if (!is_numeric($value) && empty($value)) {
                continue;
            }

            if (is_int($element_name)) {
                $child = new XMLElement('item');
                $child->setAttribute('index', $element_name + 1);
            } else {
                $child = new XMLElement($element_name, null, array(), true);
            }

            if (is_array($value) || is_object($value)) {
                self::array_to_xml($child, (array)$value);

                if ($child->getNumberOfChildren() == 0) {
                    continue;
                }
            } elseif ($validate === true && !self::validateXML(self::sanitize($value), $errors, false, new XSLTProcess)) {
                continue;
            } else {
                $child->setValue(self::sanitize($value));
            }

            $parent->appendChild($child);
        }
    }
public static function array_to_xml(XMLElement $parent, array $data, $validate = false)
    {
        foreach ($data as $element_name => $value) {
            if (!is_numeric($value) && empty($value)) {
                continue;
            }

            if (is_int($element_name)) {
                $child = new XMLElement('item');
                $child->setAttribute('index', $element_name + 1);
            } else {
                $child = new XMLElement($element_name, null, array(), true);
            }

            if (is_array($value) || is_object($value)) {
                self::array_to_xml($child, (array)$value);

                if ($child->getNumberOfChildren() == 0) {
                    continue;
                }
            } elseif ($validate === true && !self::validateXML(self::sanitize($value), $errors, false, new XSLTProcess)) {
                continue;
            } else {
                $child->setValue(self::sanitize($value));
            }

            $parent->appendChild($child);
        }
    }
public static function array_to_xml ( XMLElement $ parent , array $ data , $ validate = false ) { foreach ( $ data as $ element_name => $ value ) { if ( ! is_numeric ( $ value ) && empty ( $ value ) ) { continue ; } if ( is_int ( $ element_name ) ) { $ child = new XMLElement ( 'item' ) ; $ child -> setAttribute ( 'index' , $ element_name + 1 ) ; } else { $ child = new XMLElement ( $ element_name , null , array ( ) , true ) ; } if ( is_array ( $ value ) || is_object ( $ value ) ) { self :: array_to_xml ( $ child , ( array ) $ value ) ; if ( $ child -> getNumberOfChildren ( ) == 0 ) { continue ; } } elseif ( $ validate === true && ! self :: validateXML ( self :: sanitize ( $ value ) , $ errors , false , new XSLTProcess ) ) { continue ; } else { $ child -> setValue ( self :: sanitize ( $ value ) ) ; } $ parent -> appendChild ( $ child ) ; } }
Convert an array into an XML fragment and append it to an existing
XML element. Any arrays contained as elements in the input array will
also be recursively formatted and appended to the input XML fragment.
The input XML element will be modified as a result of calling this.

@param XMLElement $parent
the XML element to append the formatted array data to.
@param array $data
the array to format and append to the XML fragment.
@param boolean $validate
true if the formatted array data should be validated as it is
constructed, false otherwise.
Convert an array into an XML fragment and append it to an existing XML element . Any arrays contained as elements in the input array will also be recursively formatted and appended to the input XML fragment . The input XML element will be modified as a result of calling this .