将对象转换为xml,采用递归算法
@param $obj
@param int $dom
@param int $item
@return string
427190
private function objectToXml($obj, $dom = 0, $item = 0)
    {
        if (!$dom) {
            $dom = new \DOMDocument("1.0");
        }
        if (!$item) {
            $item = $dom->createElement("root");
            $dom->appendChild($item);
        }
        //var_dump($obj);
        foreach ($obj as $key => $val) {
            $itemx = $dom->createElement(is_string($key) ? $key : "item");
            $item->appendChild($itemx);

            if (!is_object($val)) {
                if (is_array($val)) {
                    $val = $this->arrToXml($val, $dom, $itemx);
                } else {
                    $text = $dom->createTextNode($val);
                    $itemx->appendChild($text);
                }
            } else {
                $this->objectToXml($val, $dom, $itemx);
            }
        }
        return $dom->saveXML();
    }
1334370
private Object newArray(Object obj, Element node) throws Exception {

		// Get the type
		Class<?> aClass = java.lang.Object.class;
		String type = getAttribute(node, "type");
		final String id = getAttribute(node, "id");
		if (type != null) {
			aClass = TypeUtil.fromName(type);
			if (aClass == null) {
				if ("String".equals(type)) {
					aClass = java.lang.String.class;
				} else if ("URL".equals(type)) {
					aClass = java.net.URL.class;
				} else if ("InetAddress".equals(type)) {
					aClass = java.net.InetAddress.class;
				} else {
					aClass = Loader.loadClass(DOMJettyWebXmlParser.class, type,
							true);
				}
			}
		}

		List<Object> al = null;

		Element[] children = getChildren(node, "Item");
		for (Element item : children) {
			String nid = getAttribute(item, "id");
			Object v = value(obj, item);

			if (al == null) {
				al = new ArrayList<>();
			}

			al.add((v == null && aClass.isPrimitive()) ? ZERO : v);
			if (nid != null) {
				_idMap.put(nid, v);
			}
		}

		Object array = toArray(al, aClass);
		if (id != null) {
			_idMap.put(id, array);
		}
		return array;
	}
341522
function(obj,parentEl) {
      
      var ul = inputEx.cn('ul', {className: 'inputEx-JsonTreeInspector'});
      
      for(var key in obj) {
         if(obj.hasOwnProperty(key)) {
            var value = obj[key];
            
            var id = Dom.generateId();
            var li = inputEx.cn('li', {id: id}, null, key+':');
            this.hash[id] = {value: value, expanded: false};
            
            
            if( lang.isObject(value) || lang.isArray(value) ) {
               if(lang.isArray(value)) {
                  li.appendChild( inputEx.cn('span', null, null, "[ "+value.length+" element"+(value.length > 1 ? 's':'')+"]" ) );
               }
               Dom.addClass(li,'collapsed');
               Event.addListener(li, 'click', this.onItemClick, this, true);
            }
            else {
               var spanContent = '';
               if( lang.isString(value) ) {
                  spanContent = '"'+inputEx.htmlEntities(value)+'"';
               }
               else {
                  if(value === null) {
                     spanContent = "null";
                  }
                  else {
                     spanContent = value.toString();
                  }
               }
               li.appendChild( inputEx.cn('span', {className: 'type-'+(value === null ? "null" : (typeof value))}, null, spanContent ) );
            }
            
            
            ul.appendChild(li);
         }
      }
      
      parentEl.appendChild(ul);
      
      return ul;
   }
223331
private static function objToStr($obj)
    {
        return method_exists($obj, '__toString') ? (string) $obj : get_class($obj) . '@' . spl_object_id($obj);
    }
1053520
public function renderXML($obj, $elemName, $attributeKeys) {
		$out = '';
		$out .= '<';
		$out .= $elemName;
		foreach ($attributeKeys as $attributeKey) {
			if (isset($obj[$attributeKey])) {
				$out .= ' ' . $attributeKey . '="' . $obj[$attributeKey] . '"';
				unset($obj[$attributeKey]);
			}
		}
		$out .= '>';
		foreach ($obj as $e => $v) {
			if (is_array($v)) {
				$out .= $this->renderXML($v, $e, $attributeKeys);
			} else {
				$out .= '<' . $e . '>' . $v . '</' . $e . '>';
			}
		}
		$out .= '<' . $elemName . '>';
		return $out;
	}
72798
protected function arrayToDomNode(\DOMDocument $dom, \DOMElement $node, array $arr)
    {
        foreach ($arr as $key => $item) {
            $ref = null;
            if (is_numeric($key) || empty($key)) {
                if (is_numeric($key)) {
                    $ref = $key;
                }
                $key = 'item';
            }
            if (is_array($item)) {
                $newNode = $dom->createElement($key);
                if (!is_null($ref)) {
                    $attr = $dom->createAttribute('ref');
                    $attr->value = $ref;
                    $newNode->appendChild($attr);
                }
                $this->arrayToDomNode($dom, $newNode, $item);
                $node->appendChild($newNode);
            } elseif (is_object($item)) {
                $this->encodeObject($key, $item, $dom, $node);
            } else {
                $node->appendChild($dom->createElement($key, $item));
            }
        }
    }
487370
public static String toXml(final Object obj) {
		final ByteArrayOutputStream out = new ByteArrayOutputStream();

		// XStream x = createXStream();
		// String xml = x.toXML(obj);
		// return xml;
		final XMLEncoder e = new XMLEncoder(out);
		e.setExceptionListener(new JKObjectUtil.XmlEncoderExceptionListener());
		// e.setPersistenceDelegate(Object.class, new MyPersistenceDelegate());
		e.writeObject(obj);
		e.close();
		return out.toString();
		// return null;
	}
314133
private function buildXml($data, \DOMDocument $doc, \DOMNode $parentNode = null)
    {
        if (is_array($data)) {
            foreach ($data as $elementName => $element) {
                if (is_int($elementName)) {
                    $elementName = 'item';
                }

                $newElement = $doc->createElement($elementName);

                if ($parentNode) {
                    $parentNode->appendChild($newElement);
                } else {
                    $doc->appendChild($newElement);
                }

                $this->buildXml($element, $doc, $newElement);
            }
        } else {
            $parentNode->nodeValue = $data;
        }
    }
348447
public function asXml(Shopgate_Model_XmlResultObject $itemNode)
    {
        /**
         * @var Shopgate_Model_XmlResultObject $manufacturerNode
         */
        $manufacturerNode = $itemNode->addChild('manufacturer');
        $manufacturerNode->addAttribute('uid', $this->getUid());
        $manufacturerNode->addChildWithCDATA('title', $this->getTitle(), false);
        $manufacturerNode->addChildWithCDATA('item_number', $this->getItemNumber(), false);

        return $itemNode;
    }
476837
public function __item($item = null)
    {
        $result = parent::__item($item);
        $result['content'] = true;
        return $result;
    }
212805
function domString( $domDocument )
    {
        $ini = eZINI::instance();
        $xmlCharset = $ini->variable( 'RegionalSettings', 'ContentXMLCharset' );
        if ( $xmlCharset == 'enabled' )
        {
            $charset = eZTextCodec::internalCharset();
        }
        else if ( $xmlCharset == 'disabled' )
            $charset = true;
        else
            $charset = $xmlCharset;
        if ( $charset !== true )
        {
            $charset = eZCharsetInfo::realCharsetCode( $charset );
        }
        $domString = $domDocument->saveXML();
        return $domString;
    }
385430
public function doLog( common_log_Item $item)
    {
        
    	$doc = new DOMDocument();
		$doc->preserveWhiteSpace = false;
		$doc->formatOutput = true;
		$success = @$doc->load($this->filename);
		if (!$success) {
            $doc->loadXML('<events></events>');
        }

		$event_element = $doc->createElement("event");

		$message = $doc->createElement("description");
		$message->appendChild(
				$doc->createCDATASection($item->getDescription())
		);
		$event_element->appendChild($message);
		
		$file = $doc->createElement("file");
		$file->appendChild(
				$doc->createCDATASection($item->getCallerFile())
		);
		$event_element->appendChild($file);
		
		$line = $doc->createElement("line");
		$line->appendChild(
				$doc->createCDATASection($item->getCallerLine())
		);
		$event_element->appendChild($line);
		
		$datetime = $doc->createElement("datetime");
		$datetime->appendChild(
				$doc->createCDATASection($item->getDateTime())
		);
		$event_element->appendChild($datetime);
		
		$severity = $doc->createElement("severity");
		$severity->appendChild(
				$doc->createCDATASection($item->getSeverity())
		);
		$event_element->appendChild($severity);

		
		$doc->documentElement->appendChild($event_element);
		@$doc->save($this->filename);
        
    }
1366650
private Object itemValue(Object obj, Object item) throws Exception {
		// String value
		if (item instanceof String) {
			return item;
		}

		Element node = (Element) item;
		String tag = node.getTagName();
		// TODO: in case of jdk7 usage use swtich instead
		if ("Call".equals(tag)) {
			return call(obj, node);
		}
		if ("Get".equals(tag)) {
			return get(obj, node);
		}
		if ("New".equals(tag)) {
			return newObj(obj, node);
		}
		if ("Ref".equals(tag)) {
			return refObj(obj, node);
		}
		if ("Array".equals(tag)) {
			return newArray(obj, node);
		}
		if ("Map".equals(tag)) {
			return newMap(obj, node);
		}
		if ("Property".equals(tag)) {
			return propertyObj(obj, node);
		}

		if ("SystemProperty".equals(tag)) {
			String name = getAttribute(node, "name");
			String defaultValue = getAttribute(node, "default");
			return System.getProperty(name, defaultValue);
		}

		LOG.warn("Unknown value tag: {}", node);
		return null;
	}
493545
public function render(\DOMDocument $domDocument)
    {
        $scriptXml  = $domDocument->createElement("script");
        $scriptText = $this->__toString();

        $scriptComment = $domDocument->createComment($scriptText);
        $scriptXml->appendChild($scriptComment);

        return $scriptXml;
    }
1273487
public function objectToDomElement($obj, DomNode $node, DomDocument $doc)
    {
        if (isset($obj->__cdata)) {
            $node->appendChild($doc->createCDATASection($obj->__cdata));
        }

        foreach ($obj as $key => &$val) {
            if (in_array($key, array('__attr', '__cdata'), true)) {
                continue;
            } elseif (is_array($val) || $val instanceof ArrayAccess) {
                foreach ($val as $k => &$v) {
                    $e = $doc->createElement($key);

                    if (is_object($v)) {
                        $this->objectToDomElement($v, $e, $doc);
                    } elseif (is_string($v) && !empty($v)) {
                        $e->appendChild($doc->createTextNode((string) $v));
                    }

                    if (isset($obj->__attr) && isset($obj->__attr[$key][$k])) {
                        foreach ((array) $obj->__attr[$key][$k] as $k2 => $v2) {
                            $e->setAttribute($k2, (string) $v2);
                        }
                    }

                    $node->appendChild($e);
                }
                continue;
            } elseif (is_object($val)) {
                $e = $this->objectToDomElement($val, $doc->createElement($key), $doc);
            } elseif ($val !== null) {
                $e = $doc->createElement($key);
                $e->appendChild($doc->createTextNode($val));
            } else {
                continue;
            }

            if (isset($obj->__attr) && isset($obj->__attr[$key])) {
                foreach ((array) $obj->__attr[$key] as $k => $v) {
                    $e->setAttribute($k, (string) $v);
                }
            }

            $node->appendChild($e);
        }

        return $node;
    }
314122
public function toXML( DOMDocument $dom )
    {
        $zoneNode = $dom->createElement( 'zone' );
        foreach ( $this->attributes as $attrName => $attrValue )
        {
            switch ( $attrName )
            {
                case 'id':
                    $zoneNode->setAttribute( 'id', 'id_' . $attrValue );
                    break;

                case 'action':
                    $zoneNode->setAttribute( 'action', $attrValue );
                    break;

                case 'blocks':
                    foreach ( $this->attributes['blocks'] as $block )
                    {
                        $blockNode = $block->toXML( $dom );
                        $zoneNode->appendChild( $blockNode );
                    }
                    break;

                default:
                    $node = $dom->createElement( $attrName );
                    $nodeValue = $dom->createTextNode( $attrValue );
                    $node->appendChild( $nodeValue );
                    $zoneNode->appendChild( $node );
                    break;
            }
        }

        return $zoneNode;
    }
275983
protected function renderSingleElementHTML(PageLayoutView $parentObject, $item)
    {
        $singleElementHTML = '';
        $unset = false;
        if (!isset($parentObject->tt_contentData['nextThree'][$item['uid']])) {
            $unset = true;
            $parentObject->tt_contentData['nextThree'][$item['uid']] = $item['uid'];
        }
        if (!$parentObject->tt_contentConfig['languageMode']) {
            $singleElementHTML .= '<div class="t3-page-ce-dragitem" id="' . StringUtility::getUniqueId() . '">';
        }
        $singleElementHTML .= $parentObject->tt_content_drawHeader(
            $item,
            $parentObject->tt_contentConfig['showInfo'] ? 15 : 5,
            $parentObject->defLangBinding,
            true,
            true
        );
        $singleElementHTML .= (!empty($item['_ORIG_uid']) ? '<div class="ver-element">' : '')
            . '<div class="t3-page-ce-body-inner t3-page-ce-body-inner-' . $item['CType'] . '">'
            . $parentObject->tt_content_drawItem($item)
            . '</div>'
            . (!empty($item['_ORIG_uid']) ? '</div>' : '');
        $singleElementHTML .= $this->tt_content_drawFooter($parentObject, $item);
        if (!$parentObject->tt_contentConfig['languageMode']) {
            $singleElementHTML .= '</div>';
        }
        if ($unset) {
            unset($parentObject->tt_contentData['nextThree'][$item['uid']]);
        }

        return $singleElementHTML;
    }