-
-
Save dirkakrid/e25243cd5ddbb40f9360d82b8674cb09 to your computer and use it in GitHub Desktop.
Using pyez's remove_namespaces function to strip namespace information
This file contains hidden or 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