解析xml并取消设置节点

解析xml并取消设置节点,xml,Xml,如何解析xml并获取节点。您可以使用json\u decode解码字符串,使用递归函数删除所有非活动元素,最后json\u encode将数组还原为json字符串 $json = json_decode($data, true); $json['categoryTree'] = filter_inactive($json['categoryTree']); echo json_encode($json); function filter_inactive($data) { $t = a

如何解析xml并获取节点。

您可以使用
json\u decode
解码字符串,使用递归函数删除所有非活动元素,最后
json\u encode
将数组还原为json字符串

$json = json_decode($data, true);
$json['categoryTree'] = filter_inactive($json['categoryTree']);
echo json_encode($json);

function filter_inactive($data) {
    $t = array();
    foreach ($data as $child) {
        if ($child['is_active'] == '1') {
            if (isset($child['children'])) {
                $child['children'] = filter_inactive($child['children']);
            }
            $t[] = $child;
        }
    }

    return $t;
}

你试过什么?您的标记令人困惑-node.js与此有什么关系?尝试了json_decode()?使用decode json和递归树迭代器