Search code examples
xmlscriptingxmllintinfoblox

xmllint - Help formulating a query. ( XPath set is empty ) error


I have the output from an ( INFOBLOX ) IP lookup and want to manipulate the output. I can't seem to formulate the correct syntax to pull the IP address out of the ( .xml ) output.

I am trying to pull out the <ipv4addr> tag but everything I have tried so far returns XPath set is empty.

# cat test.xml | xmllint --xpath "//ipv4addr/value/text()" -
XPath set is empty
[ test.xml ]

<?xml version="1.0"?>
<list>
  <value type="object">
    <name>idrac-layton-jasmine.ecs.fln.lab.emc.com</name>
    <ipv4addrs>
      <list>
        <value type="object">
          <configure_for_dhcp type="boolean">true</configure_for_dhcp>
          <_ref>record:host_ipv4addr/ZG5zLmhvc3RfYWRkcmVzcyQuX2RlZmF1bHQuY29tLmVtYy5sYWIuZmxuLmVjcy5pZHJhYy1sYXl0b24tamFzbWluZS4xMC4yMzYuMjI3LjExMC4:10.236.227.110/idrac-layton-jasmine.ecs.fln.lab.emc.com/default</_ref>
          <mac>2c:ea:7f:5c:9c:67</mac>
          <ipv4addr>10.236.227.110</ipv4addr>
          <host>idrac-layton-jasmine.ecs.fln.lab.emc.com</host>
        </value>
      </list>
    </ipv4addrs>
    <_ref>record:host/ZG5zLmhvc3QkLl9kZWZhdWx0LmNvbS5lbWMubGFiLmZsbi5lY3MuaWRyYWMtbGF5dG9uLWphc21pbmU:idrac-layton-jasmine.ecs.fln.lab.emc.com/default</_ref>
    <view>default</view>
  </value>
</list>

I was expecting the command to return ( 10.236.227.110 )


Solution

  • Try changing your xpath expression to

    "//ipv4addr/text()"
    

    and see if it works.