XML编码
@param mixed $data 数据
@param string $root 根节点名
@param string $item 数字索引的子节点名
@param string $id 数字索引子节点key转换的属性名
@return string
322459
static public function arr2xml($data, $root = 'xml', $item = 'item', $id = 'id')
    {
        return "<{$root}>" . self::_data_to_xml($data, $item, $id) . "</{$root}>";
    }
1301310
protected function generateItemXmlString(Parts\Item $item, DOMDocument $dom)
    {
        $itemNode = $dom->createElement('item');

        foreach ($item->getState() as $attrName => $attrValue) {
            switch ($attrName) {
                case 'action':
                    if ($attrValue !== null) {
                        $itemNode->setAttribute('action', $attrValue);
                    }
                    break;
                case 'contentId':
                    $this->addNewNotEmptyXmlElement($dom, $itemNode, 'object_id', $attrValue);
                    break;
                case 'locationId':
                    $this->addNewNotEmptyXmlElement($dom, $itemNode, 'node_id', $attrValue);
                    break;
                case 'priority':
                    $this->addNewNotEmptyXmlElement($dom, $itemNode, 'priority', $attrValue);
                    break;
                case 'publicationDate':
                    $this->addNewNotEmptyXmlElement($dom, $itemNode, 'ts_publication', $attrValue);
                    break;
                case 'visibilityDate':
                    $this->addNewNotEmptyXmlElement($dom, $itemNode, 'ts_visible', $attrValue);
                    break;
                case 'hiddenDate':
                    $this->addNewNotEmptyXmlElement($dom, $itemNode, 'ts_hidden', $attrValue);
                    break;
                case 'rotationUntilDate':
                    $this->addNewNotEmptyXmlElement($dom, $itemNode, 'rotation_until', $attrValue);
                    break;
                case 'movedTo':
                    $this->addNewNotEmptyXmlElement($dom, $itemNode, 'moved_to', $attrValue);
                    break;
                case 'attributes':
                    foreach ($attrValue as $arrayItemKey => $arrayItemValue) {
                        $this->addNewNotEmptyXmlElement($dom, $itemNode, $arrayItemKey, $arrayItemValue);
                    }
                    break;
            }
        }

        return $itemNode;
    }
1125190
public static function getTreeChild($data, $parent_id, $key = 'parent_id', $id_key = 'id') {
		$result = [];
		$args   = [$parent_id];
		do {
			$kids = [];
			$flag = false;
			foreach ($args as $fid) {
				for ($i = count($data) - 1; $i >=0 ; $i --) {
					$node = $data[$i];
					if ($node[$key] == $fid) {
						array_splice($data, $i , 1);
						$result[] = $node[$id_key];
						$kids[]   = $node[$id_key];
						$flag     = true;
					}
				}
			}
			$args = $kids;
		} while($flag === true);
		return $result;
	}
766913
public function &createXML($node_name, $data = [])
    {
        $xml = $this->getXMLRoot();
        $xml->appendChild($this->convert($node_name, $data));
        $this->xml = null;    // clear the xml node in the class for 2nd time use.
        return $xml;
    }
414946
public static function build(
        $data,
        $root = 'xml',
        $item = 'item',
        $attr = '',
        $id = 'id'
    ) {
        if (is_array($attr)) {
            $_attr = array();

            foreach ($attr as $key => $value) {
                $_attr[] = "{$key}=\"{$value}\"";
            }

            $attr = implode(' ', $_attr);
        }

        $attr = trim($attr);
        $attr = empty($attr) ? '' : " {$attr}";
        $xml = "<{$root}{$attr}>";
        $xml  .= self::data2Xml($data, $item, $id);
        $xml  .= "</{$root}>";

        return $xml;
    }
21686
public function toXML($CD_DATA = false,$rootName = 'xml',$encoding = 'UTF-8')
    {
        $data = $this->getArrayCopy();
        if($CD_DATA){
            /*
             * 默认制定
             */
            $xml = new class('<?xml version="1.0" encoding="'.$encoding.'" ?>'."<{$rootName}></{$rootName}>") extends \SimpleXMLElement{
                public function addCData($cdata_text) {
                    $dom = dom_import_simplexml($this);
                    $cdata = $dom->ownerDocument->createCDATASection($cdata_text);
                    $dom->appendChild($cdata);
                }
            };
        }else{
            $xml = new \SimpleXMLElement('<?xml version="1.0" encoding="'.$encoding.'" ?>'."<{$rootName} ></{$rootName}>");
        }
        $parser = function ($xml,$data)use(&$parser,$CD_DATA){
            foreach($data as $k => $v){
                if(is_array($v)) {
                    if (!is_numeric($k)){
                        $ch= $xml->addChild($k);
                    } else{
                        $ch = $xml->addChild(substr($xml->getName(),0,-1));
                    }
                    $parser($ch,$v);
                } else {
                    if (is_numeric($k)){
                        $xml->addChild($k, $v);
                    }else{
                        if($CD_DATA){
                            $n = $xml->addChild($k);
                            $n->addCData($v);
                        }else{
                            $xml->addChild($k, $v);
                        }
                    }
                }
            }
        };
        $parser($xml,$data);
        unset($parser);
        $str = $xml->asXML();
        return substr($str,strpos($str,"\n")+1);
    }
580981
public function toXML($data)
    {
        $root = isset($data['root']) ? $data['root'] : $this->module;
        $no = 1;
        $xml = '<'.$root.'>';
        if (isset($data['options'])) {
            $xml .= '<row no="'.$no.'">';
            foreach ($data['options'] as $key => $value) {
                $xml .= '<option val="'.$key.'">'.$value.'</option>';
            }
            $xml .= '</row>';
            ++$no;
        }
        foreach ($data['records'] as $row) {
            $xml .= '<row no="'.$no.'">';
            foreach ($row as $key => $value) {
                if (is_array($value)) {
                    $xml .= '<FL val="'.str_replace('&', 'and', $key).'">';
                    foreach ($value as $k => $v) {
                        list($tag, $attribute) = explode(' ', $k);
                        $xml .= '<'.$tag.' no="'.$attribute.'">';
                        foreach ($v as $kk => $vv) {
                            $xml .= '<FL val="'.str_replace('&', 'and', $kk).'"><![CDATA['.$vv.']]></FL>';
                        }
                        $xml .= '</'.$tag.'>';
                    }
                    $xml .= '</FL>';
                } else {
                    $xml .= '<FL val="'.str_replace('&', 'and', $key).'"><![CDATA['.$value.']]></FL>';
                }
            }
            $xml .= '</row>';
            ++$no;
        }
        $xml .= '</'.$root.'>';

        return $xml;
    }
1009630
public function getRootItem($id)
    {
        return isset($this->menuRootItems[$id]) ? $this->menuRootItems[$id] : null;
    }
1137832
public static Document mapToXml(Map<?, ?> data, String rootName) {
		final Document doc = createXml();
		final Element root = appendChild(doc, rootName);

		mapToXml(doc, root, data);
		return doc;
	}
575419
public function findTreeItem($id, MapperTreeItemInterface $item)
    {
        if ($id === $item->getId()) {
            return $item;
        }
        foreach ($item->getChildren() as $child) {
            if (null !== $treeItem = $this->findTreeItem($id, $child)) {
                return $treeItem;
            }
        }

        return null;
    }
485377
public static function arrayToXml($data, $root = null, $level = 1, $format = true)
    {
        if (empty($root)) {
            $root = config('df.xml_root', 'dfapi');
        }

        return '<?xml version="1.0" ?>' . static::arrayToXmlInternal($data, $root, $level, $format);
    }
1339351
public function saveById($id, $data)
    {
        $subData = array();
        foreach (array_keys($this->subAttributeList) as $subKey) {
            $subData[$subKey] = null;
            if (isset($data[$subKey])) {
                $subData[$subKey] = $data[$subKey];
                unset($data[$subKey]);
            }
        }
        $id = parent::saveById($id, $data);
        foreach (array_keys($this->subAttributeList) as $subKey) {
            $this->saveSubAttributeById($id, $subKey, $subData[$subKey]);
        }
        return $id;
    }
814394
protected static function parseRecursive( $type, &$root, &$lines )
	{
		$node = new XML_DOM_Node( strtolower( $type ) );
		$root->addChild( $node );
		while( count( $lines ) )
		{
			$line	= array_shift( $lines );
			$parsed	= self::parseLine( $line );
			if( $parsed['name'] == "END" && $parsed['value'] == $type )
				return $lines;
			else if( $parsed['name'] == "BEGIN" )
				$lines	= self::parseRecursive( $parsed['value'], $node, $lines );
			else
			{
				$child	= new XML_DOM_Node( strtolower( $parsed['name'] ), $parsed['value'] );
				foreach( $parsed['param'] as $param )
				{
					$parts	= explode( "=", $param );
					$child->setAttribute( strtolower( $parts[0] ), $parts[1] );
				}
				$node->addChild( $child );
			}
		}
	}
98747
public function item($resourceKey, array $data)
    {
        $id = $this->getIdFromData($data);

        $resource = [
            'data' => [
                'type' => $resourceKey,
                'id' => "$id",
                'attributes' => $data,
            ],
        ];

        unset($resource['data']['attributes']['id']);

        if(isset($resource['data']['attributes']['links'])) {
            $custom_links = $data['links'];
            unset($resource['data']['attributes']['links']);
        }

        if (isset($resource['data']['attributes']['meta'])){
            $resource['data']['meta'] = $data['meta'];
            unset($resource['data']['attributes']['meta']);
        }

        if(empty($resource['data']['attributes'])) {
            $resource['data']['attributes'] = (object) [];
        }

        if ($this->shouldIncludeLinks()) {
            $resource['data']['links'] = [
                'self' => "{$this->baseUrl}/$resourceKey/$id",
            ];
            if(isset($custom_links)) {
                $resource['data']['links'] = array_merge($resource['data']['links'], $custom_links);
            }
        }

        return $resource;
    }
125254
public static function buildJsonFromArray($data, $rootElement = '')
    {
        if (!is_array($data)) {
            return null;
        }

        if (!empty($rootElement)) {
            $data = array($rootElement => $data);
        }

        $data = self::setSenderProperty($data);

        return json_encode($data);
    }
715400
public function get($id, $rootId=NULL, array $columns=[])
    {
        $columns = $this->pickColumns($columns);
        $columnsId = $this->getColumnsCacheId($columns);

        if (isset($this->_hierachyCache[$columnsId][$id])) {
            return $this->_hierachyCache[$columnsId][$id];
        }

        // If we have a root id, fill the cache by fetching the whole tree
        if ($rootId) {
            $this->tree($rootId, $columns);
        }

        // After retrieving the tree, look if it is now in cache
        if (isset($this->_hierachyCache[$columnsId][$id])) {
            return $this->_hierachyCache[$columnsId][$id];
        }

        $result = $this->queryTreeById($id)
                       ->get($this->toSelectColumns($columns));

        $this->fillNodeCache($columnsId, $result);

        if (isset($this->_hierachyCache[$columnsId][$id])) {
            return $this->_hierachyCache[$columnsId][$id];
        }

    }
793645
public function item($data, $transformer = null, $resourceName = null)
    {
        if (! is_null($resourceName)) {
            $this->resourceName = $resourceName;
        }

        return $this->data('item', $data, $transformer);
    }