Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to pass xml to xmllint in a variable instead of a file?

Tags:

shell

i want to do this

xmllint --xpath "//filestodelete[filename = somename]/text()" #filestodelete#  

and filestodelete is a BPEL variable of type XML

but it does not work

how to do this>??

like image 719
sakal Avatar asked Oct 17 '25 15:10

sakal


1 Answers

Assuming you've put your query text in a shell variable named query (to make my examples terser) --

With bash, you can use a herestring:

xmllint --xpath "$query" - <<<"$filestodelete"

With POSIX sh, you need to use a heredoc:

xmllint --xpath "$query" - <<EOF
$filestodelete
EOF

By the way -- since not all versions of xmllint support --xpath, you'd have better compatibility across releases if you used XMLStarlet instead, which has supported the following from its initial creation:

xmlstarlet sel -t -m "$query" -v . <<<"$filestodelete"
like image 86
Charles Duffy Avatar answered Oct 19 '25 14:10

Charles Duffy