Skip to content

helper

scrapli_netconf.helper

remove_namespaces(tree: Element) -> Element

Remove all namespace tags from Element object

Replace element tags like: {http://cisco.com/ns/yang/Cisco-IOS-XR-ipv4-bgp-oper}connection-state With: connection-state

Parameters:

Name Type Description Default
tree Element

lxml Element

required

Returns:

Name Type Description
Element Element

lxml Element with namespaces stripped out

Source code in scrapli_netconf/helper.py
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
def remove_namespaces(tree: Element) -> Element:
    """
    Remove all namespace tags from Element object

    Replace element tags like: {http://cisco.com/ns/yang/Cisco-IOS-XR-ipv4-bgp-oper}connection-state
    With: connection-state

    Args:
        tree: lxml Element

    Returns:
        Element: lxml Element with namespaces stripped out

    Raises:
        N/A

    """
    for el in tree.getiterator():
        if not hasattr(el.tag, "find"):
            continue
        el.tag = re.sub(r"^{.*}", "", el.tag)
    objectify.deannotate(tree, cleanup_namespaces=True)
    return tree