Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

extracting nodes values with xmlstarlet

Tags:

xmlstarlet

i have this xml schema , what i want is how to extract the values of all the nodes one by one, using XMLStarlet , in shell script

     <service>
        <imageScroll>
           <imageName>Photo_Gallerie_1.jpg</imageName>
        </imageScroll>
        <imageScroll>
           <imageName>Photo_Gallerie_2.jpg</imageName>
        </imageScroll>
        <imageScroll>
           <imageName>Photo_Gallerie_3.jpg</imageName>
        </imageScroll>
      </service>
like image 537
wissem46 Avatar asked Jun 02 '14 15:06

wissem46


1 Answers

xmlstarlet sel -t -m "//imageName" -v . -n your.xml

output:

Photo_Gallerie_1.jpg
Photo_Gallerie_2.jpg
Photo_Gallerie_3.jpg

Is that what you needed?

  • sel (select mode)
  • -t (output template(this is pretty much required)
  • -m (for each match of the following value)
    • "// (the double slash means it could be anywhere in the tree)
    • imageName (name of node you want)"
  • -v (requests the value of an element in the current path) and the . represents current element in iteration (you could put the name of the node there but it's generally easier this way) and then the
  • -n is to add a line for every value you match.
like image 70
Dustin Glover Avatar answered Sep 28 '22 17:09

Dustin Glover