Beispiel #1
0
 /**
 * 增加节点值
 * @param array $data
 * @param SimpleXMLElement $xml
 * 
 * @return void
 */
 public static function node($data, SimpleXMLExtended &$xml)
 {
     foreach ($data as $k => $v) {
         if (is_array($v)) {
             is_numeric($k) && ($k = substr($xml->getName(), 0, -1));
             $subroot = $xml->addChild($k);
             self::node($v, $subroot);
         } else {
             if (is_numeric($v)) {
                 $xml->addChild($k, $v);
             } else {
                 $xml->addChild($k)->addCData($v);
             }
         }
     }
 }
 public function addXMLElement(SimpleXMLExtended $source)
 {
     $new_dest = $this->addChild($source->getName(), strval($source));
     foreach ($source->attributes() as $key => $value) {
         if ($key != 'isCDATA') {
             $new_dest->addAttribute($key, $value);
         }
     }
     foreach ($source->children() as $child) {
         $new_dest->addXMLElement($child);
     }
 }