napalm_yang/parsers/xml_deprecated.py
def _parse_list_nested_recursive(
        cls, data, path, iterators, list_vars, cur_vars=None
    ):
        """
        This helps parsing shit like:

            <protocols>
                <bgp>
                    <group>
                        <name>my_peers</name>
                        <neighbor>
                            <name>192.168.100.2</name>
                            <description>adsasd</description>
                            <peer-as>65100</peer-as>
                        </neighbor>
                        <neighbor>
                            <name>192.168.100.3</name>
                            <peer-as>65100</peer-as>
                        </neighbor>
                    </group>
                    <group>
                        <name>my_other_peers</name>
                        <neighbor>
                            <name>172.20.0.1</name>
                            <peer-as>65200</peer-as>
                        </neighbor>
                    </group>
                </bgp>
            </protocols>

        """
        cur_vars = dict(cur_vars) if cur_vars else {}
        if path:
            p = path[0]
            path = path[1:]
        else:
            for _ in data:
                list_vars.append(cur_vars)
            iterators.append(data)
            return data

        if p.startswith("?"):
            for x in data:
                key, var_path = p.split(".")
                cur_vars.update({key.lstrip("?"): x.xpath(var_path)[0].text})
                cls._parse_list_nested_recursive(
                    x, path, iterators, list_vars, cur_vars
                )
        else:
            x = data.xpath(p)
            cls._parse_list_nested_recursive(x, path, iterators, list_vars, cur_vars)
def _parse_list_nested_recursive(
        cls, data, path, iterators, list_vars, cur_vars=None
    ):
        """
        This helps parsing shit like:

            <protocols>
                <bgp>
                    <group>
                        <name>my_peers</name>
                        <neighbor>
                            <name>192.168.100.2</name>
                            <description>adsasd</description>
                            <peer-as>65100</peer-as>
                        </neighbor>
                        <neighbor>
                            <name>192.168.100.3</name>
                            <peer-as>65100</peer-as>
                        </neighbor>
                    </group>
                    <group>
                        <name>my_other_peers</name>
                        <neighbor>
                            <name>172.20.0.1</name>
                            <peer-as>65200</peer-as>
                        </neighbor>
                    </group>
                </bgp>
            </protocols>

        """
        cur_vars = dict(cur_vars) if cur_vars else {}
        if path:
            p = path[0]
            path = path[1:]
        else:
            for _ in data:
                list_vars.append(cur_vars)
            iterators.append(data)
            return data

        if p.startswith("?"):
            for x in data:
                key, var_path = p.split(".")
                cur_vars.update({key.lstrip("?"): x.xpath(var_path)[0].text})
                cls._parse_list_nested_recursive(
                    x, path, iterators, list_vars, cur_vars
                )
        else:
            x = data.xpath(p)
            cls._parse_list_nested_recursive(x, path, iterators, list_vars, cur_vars)
This helps parsing shit like:

            <protocols>
                <bgp>
                    <group>
                        <name>my_peers</name>
                        <neighbor>
                            <name>192.168.100.2</name>
                            <description>adsasd</description>
                            <peer-as>65100</peer-as>
                        </neighbor>
                        <neighbor>
                            <name>192.168.100.3</name>
                            <peer-as>65100</peer-as>
                        </neighbor>
                    </group>
                    <group>
                        <name>my_other_peers</name>
                        <neighbor>
                            <name>172.20.0.1</name>
                            <peer-as>65200</peer-as>
                        </neighbor>
                    </group>
                </bgp>
            </protocols>