xpath query to process XML output
xpath query to process XML output
I am trying to process some XML output on a Juniper router through slax. The following is the XML data that I am working on.
<filesystem>
<filesystem-name>/dev/ad2s1f</filesystem-name>
<total-blocks junos:format="34G">70754788</total-blocks>
<used-blocks junos:format="5.6G">11800836</used-blocks>
<available-blocks junos:format="25G">53293572</available-blocks>
<used-percent> 18</used-percent>
<mounted-on>/var</mounted-on>
</filesystem>
I want to get available-blocks
attribute value of "25G"
. @attribute
is not working for me or my syntax is wrong. Can anyone help with a xpath query? I'm looking for something like this:
available-blocks
"25G"
@attribute
var $test = $var_data/available-blocks[@*];
1 Answer
1
Is your xmlns defined? Then it should be as easy as:
<configuration xmlns:junos="junos">
<filesystem>
<filesystem-name>/dev/ad2s1f</filesystem-name>
<total-blocks junos:format="34G">70754788</total-blocks>
<used-blocks junos:format="5.6G">11800836</used-blocks>
<available-blocks junos:format="25G">53293572</available-blocks>
<used-percent> 18</used-percent>
<mounted-on>/var</mounted-on>
</filesystem>
</configuration>
Xpath 2.0:
//available-blocks/@*
Online Demo
@student_XML786 You are welcomed. Feel free to upvote once reach the required 15 repo. Up'd.
– wp78de
Jul 3 at 5:39
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Thanks that worked :)
– student_XML786
Jul 3 at 5:36