Skip to content

Instantly share code, notes, and snippets.

@jeffbrl
Last active February 14, 2017 03:37
Show Gist options
  • Save jeffbrl/837f7fe12e1da4123a2f to your computer and use it in GitHub Desktop.
Save jeffbrl/837f7fe12e1da4123a2f to your computer and use it in GitHub Desktop.
Using pyez's remove_namespaces function to strip namespace information
from lxml import etree
from jnpr.junos.jxml import remove_namespaces
# file contains output of 'show interfaces ge-0/0/0.0'
fh = open('router_output2.xml', 'r')
parser = etree.XMLParser(remove_blank_text=True)
tree = etree.parse(fh, parser)
tree = remove_namespaces(tree)
xpath = "//logical-interface/address-family[address-family-name = 'inet']/interface-address/ifa-local"
tree_list = tree.xpath(xpath)
if tree_list:
print tree_list[0].text.strip()
else:
print "xpath expression did not match"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment