bash script to read & store xml value -


i have xml file retrieve filepath value , store variable use launch app. here's xml file:

<?xml version="1.0"?> <resultset statement="select * dms.gamthr_exp " xmlns:xsi="http://www.w3.org/2001/xmlschema-instance">   <row>     <field name="id">1</field>     <field name="filepath">/home/drs/videos/game.of.thrones/game.of.thrones.s01e01.mkv</field>  </row> </resultset> 

i have pieced script not working:

#!/bin/bash myvar=$(echo 'cat //row/field[@name="filepath"]/@value' | xmllint --shell /home/drs/dms/gamthr.xml | awk -f'[="]' '{print $(nf-1)}')  vlc --fullscreen "$myvar" 

any getting work appreciated!

to select text node of context node, use text() node test:

//row/field[@name="filepath"]/text() 

use --xpath option of xmllint pass xpath:

xmllint --xpath '//row/field[@name="filepath"]/text()' /home/drs/dms/gamthr.xml 

finally script should like:

#!/bin/bash  myvar=$(xmllint --xpath '//row/field[@name="filepath"]/text()' /home/drs/dms/gamthr.xml)  vlc --fullscreen "$myvar" 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -