Last active
February 14, 2017 03:37
-
-
Save jeffbrl/837f7fe12e1da4123a2f to your computer and use it in GitHub Desktop.
Using pyez's remove_namespaces function to strip namespace information
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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