I have the following HTML code:
This is a wrapper script intended exactly to the purpose of newlines delimited output (for old releases of xmllint):
#!/bin/bash
# wrapper script to
# - have newline delimited output on Xpath querys
# - implements --xpath on very old releases
/usr/bin/xmllint --xpath &>/dev/null
implements_xpath=$?
newlines_delimited_xmllint_version=20909
current_version=$(xmllint --version |& awk 'NR==1{print $NF;exit}')
args=( "$@" )
if [[ $@ == *--xpath* ]]; then
# iterate over positional parameters
for ((i=0; i<${#args}; i++)); do
if [[ ${args[i]} == --xpath ]]; then
xpath="${args[i+1]}"
unset args[i+1]
unset args[i]
break
fi
done
if [[ ($implements_xpath==0 && $current_version>=20909) || $file == - || $file == /dev/stdin || $xpath == / || $xpath == string\(* ]]
then
exec /usr/bin/xmllint "$@"
else
exec /usr/bin/xmllint "${args[@]}" --shell <<< "cat $xpath" | sed '1d;$d;s/^ ------- *$//;/^$/d'
fi
else
exec /usr/bin/xmllint "$@"
fi
Check latest revision: https://github.com/sputnick-dev/xmllint
Debian Buster in June 29 2020 have version 2.9.4 which is 4 years old.
Debian testing/experimental have 2.9.10, which is the fixed version.
Another way to install 2.9.10 with Debian last stable: https://serverfault.com/a/1022826/120473 (without taking the risk of crashing the apt system)