org\transform\driver\Xml::xml2data PHP 메소드

xml2data() 공개 정적인 메소드

数据XML解码
public static xml2data ( SimpleXMLElement $xml, array &$data, string $item = 'item', string $id = 'id' )
$xml SimpleXMLElement xml对象
$data array 解码后的数据
$item string 数字索引时的节点名称
$id string 数字索引key转换为的属性名
    public static function xml2data(SimpleXMLElement $xml, &$data, $item = 'item', $id = 'id')
    {
        foreach ($xml->children() as $items) {
            $key = $items->getName();
            $attr = $items->attributes();
            if ($key == $item && isset($attr[$id])) {
                $key = strval($attr[$id]);
            }
            if ($items->count()) {
                self::xml2data($items, $val);
            } else {
                $val = strval($items);
            }
            $data[$key] = $val;
        }
    }