Re: Is there a solution to have newline delimited output for xmllint ?

[email protected]
Newsgroups gmane.comp.gnome.lib.xml.general
Message-ID <[email protected]>
My implementation of a wrapper command, named xmllint :

-------8<------------------
#!/bin/bash

# 2018-03-23 12:49:27.0 +0100 / Gilles Quenot 
<[email protected]>
# wrapper script to have newline delimited output on Xpath querys

args=( "$@" )
if [[ $@ == *--xpath* ]]; then
     # iterate over positional parameters
     for ((i=0; i<${#args}; i++)); do
         if [[ ${args[i]} == --xpath ]]; then
             xpath="${args[i+1]}"
             delete=("${args[i+1]}" "${args[i]}")
         elif [[ -e ${args[i]} || ${args[i]} == file://* || ${args[i]} == 
http*://* || ${args[i]} == - ]]; then
             file="${args[i]}"
             delete=("${args[i]}")
             break
         fi
     done
     if [[ $file == - ]]; then
         /usr/bin/xmllint "$@"
     else
         /usr/bin/xmllint "$args" --shell "${file}" <<< "cat $xpath" | 
sed '1d;$d;s/^ ------- *$//;/^$/d; s/^ *//'
     fi
else
     /usr/bin/xmllint "$@"
fi
-------8<------------------

regards, Gilles Quenot
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.