how to pass xml to xmllint in a variable instead o

2019-07-04 00:03发布

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>??

标签: shell
1条回答
Anthone
2楼-- · 2019-07-04 00:26

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"
查看更多
登录 后发表回答