'; $xml .= '<' . $node_block . '>'; if ( $wrap_json ) { $xml .= ''; } else { $xml .= self::_generate_xml_from_value( $data, $node_name ); } $xml .= ''; return $xml; } /** * Serializes $value into an XML document fragment. * * Function adapted from * http://www.sean-barton.co.uk/2009/03/turning-an-array-or-object-into-xml-using-php/ * * @param mixed $array Value to serialize. * @param string $node_name Name of XML element to wrap around ordinal array elements. * @return string Valid XML document. */ private static function _generate_xml_from_value( $value, $node_name ) { if ( is_array( $value ) || is_object( $value ) ) { $xml = ''; foreach ( $value as $key => $value ) { if ( is_numeric( $key ) ) { $key = $node_name; } $xml .= '<' . $key . '>' . self::_generate_xml_from_value( $value, $node_name ) . ''; } } else { $xml = htmlspecialchars( $value, ENT_QUOTES ); } return $xml; } }