Beispiel #1
0
 /**
  * Converts an array into DOMDocument
  *
  * @param array|object $array The array to convert
  * @param DOMDocument $dom The document
  * @param DOMElement|DOMNodeList $parent Parent element in the $dom
  * @return void
  */
 protected function array_to_dom($array, $dom, $parent)
 {
     foreach ($array as $key => $value) {
         if (is_array($value) || is_object($value)) {
             if (!ctype_digit((string) $key)) {
                 $element = $dom->createElement($key);
                 $parent->appendChild($element);
             } else {
                 $element = $parent;
             }
             $this->array_to_dom($value, $dom, $element);
         } else {
             if (!ctype_digit((string) $key)) {
                 if ($value === false) {
                     $value = 0;
                 } elseif ($value === true) {
                     $value = 1;
                 }
                 $element = $dom->createElement($key);
                 $element->appendChild($dom->createTextNode($value));
                 $parent->appendChild($element);
             }
         }
     }
 }