protected function generateXml(\DOMDocument $doc, $data)
	{
		if (is_array($data) && range(0, count($data) - 1) == array_keys($data)) {
			// $data is a regular indexed array
			$array = $doc->createElement('array');

			foreach ($data as $value) {
				$entry = $doc->createElement('item');
				$entry->appendChild($this->generateXml($doc, $value));

				$array->appendChild($entry);
			}

			return $array;
		}
		else if (is_array($data) || is_object($data)) {
			// $data is an associative array or object
			$map = $doc->createElement('map');

			foreach ($data as $key => $value) {
				$entry = $doc->createElement('item');
				$entry->setAttribute('key', $key);
				$entry->appendChild($this->generateXml($doc, $value));

				$map->appendChild($entry);
			}

			return $map;
		}
		else {
			// $data is a primitive type
			return $doc->createTextNode($data);
		}
	}
protected function generateXml(\DOMDocument $doc, $data)
	{
		if (is_array($data) && range(0, count($data) - 1) == array_keys($data)) {
			// $data is a regular indexed array
			$array = $doc->createElement('array');

			foreach ($data as $value) {
				$entry = $doc->createElement('item');
				$entry->appendChild($this->generateXml($doc, $value));

				$array->appendChild($entry);
			}

			return $array;
		}
		else if (is_array($data) || is_object($data)) {
			// $data is an associative array or object
			$map = $doc->createElement('map');

			foreach ($data as $key => $value) {
				$entry = $doc->createElement('item');
				$entry->setAttribute('key', $key);
				$entry->appendChild($this->generateXml($doc, $value));

				$map->appendChild($entry);
			}

			return $map;
		}
		else {
			// $data is a primitive type
			return $doc->createTextNode($data);
		}
	}
protected function generateXml ( \ DOMDocument $ doc , $ data ) { if ( is_array ( $ data ) && range ( 0 , count ( $ data ) - 1 ) == array_keys ( $ data ) ) { // $data is a regular indexed array $ array = $ doc -> createElement ( 'array' ) ; foreach ( $ data as $ value ) { $ entry = $ doc -> createElement ( 'item' ) ; $ entry -> appendChild ( $ this -> generateXml ( $ doc , $ value ) ) ; $ array -> appendChild ( $ entry ) ; } return $ array ; } else if ( is_array ( $ data ) || is_object ( $ data ) ) { // $data is an associative array or object $ map = $ doc -> createElement ( 'map' ) ; foreach ( $ data as $ key => $ value ) { $ entry = $ doc -> createElement ( 'item' ) ; $ entry -> setAttribute ( 'key' , $ key ) ; $ entry -> appendChild ( $ this -> generateXml ( $ doc , $ value ) ) ; $ map -> appendChild ( $ entry ) ; } return $ map ; } else { // $data is a primitive type return $ doc -> createTextNode ( $ data ) ; } }
Generate a xml element from the input data.

@param \DOMDocument $doc
@param mixed        $data

@return \DOMElement
Generate a xml element from the input data .