FreeKB - Linux Commands xml_grep (parse XML file)
Linux Commands - xml_grep (parse XML file)

Let's say example.xml contains the following.

<items>
  <id>123</id>
  <item>Shoes</item>
  <id>456</id>
  <item>Boots</item>
</items>

 

The xml_grep command can be used to parse the XML file. In this example, the item tags are parsed.

xml_grep 'item' example.xml

 

Which should return the following output.

<?xml version="1.0" ?>
<xml_grep version="0.9" date="Thu Aug 17 20:59:36 2017">
<file filename="example.xml">
  <item>Shoes</item>
  <item>Boots</item>
</file>
</xml_grep>

 

--text_only can be used to only display the value in a certain XML tag.

xml_grep 'item' example.xml --text_only

 

Which should return the following.

Shoes
Boots

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter e5da3 in the box below so that we can be sure you are a human.




Comments


September 16th, 2020 by Ramnath
Thank you

Web design by yours truely - me, myself, and I   |   jeremy.canfield@freekb.net   |