Re: [xml] Is there a solution to have newline delimited output for xmllint ?
I have a program I pre-process and post-process all my XML. One of the main thing it does is fix CR/LF versus CR versus LF ... in some cases where people send me XML all in one string (UGLY) I simply load it and write it back out with libxml2 ... now it is formatted pretty with correct CR/LF :-) Often it is easier to work around a problem than try and get the kitchen sink into something like libxml2. Particularly since in our case we have customers doing it every way it is possible and some that are not. One company (a big box) puts attributes all crammed together with no white space (should be a space between each attribute) -- we can't change them so my pre-processor does it. Another puts & at the end of each line (I expect their software has a black box to output and they are doing it as if it was a URL which use & as a separator). Yeah -- they become LF on our Unix box. We even wrote ours to accept any case mix (because they are too dumb to read specs and see orderNumber instead of OrderNumber -- as long as the XML is valid we just ignore case on the test. Saves a lot of support calls. With thousands of customers sending in XML I think I've seen most boneheaded things and just fixing it to allow for boneheads reduces support a lot! I do have a standalone program to do the CR/LF stuff and XML formatting ... you are welcome to it. It won't work directly because it uses some libraries I have I can't easily separate out -- but you could easily figure it out (example we have a function to read command line switches as probably everyone does). Let me know if you want it. Eric -Original Message- From: xml [mailto:xml-boun...@gnome.org] On Behalf Of gilles.que...@sputnick.fr Sent: Sunday, September 23, 2018 6:13 AM To: Nick Wellnhofer Cc: xml@gnome.org Subject: Re: [xml] Is there a solution to have newline delimited output for xmllint ? > On 20/03/2018 16:45, Nick Wellnhofer wrote: > This should be resolved now: > > > https://gitlab.gnome.org/GNOME/libxml2/commit/da35eeae5b92b88d8ebdb64b > 4b327ac1c2cf1bce > Nice, thanks. This is the official libxml repository I guess(?). Do you know if a Debian package will be packaged ? I will contact Archlinux mainteners to update package, last update 2016. Regards, Gilles Quenot ___ xml mailing list, project page http://xmlsoft.org/ xml@gnome.org https://mail.gnome.org/mailman/listinfo/xml ___ xml mailing list, project page http://xmlsoft.org/ xml@gnome.org https://mail.gnome.org/mailman/listinfo/xml
Re: [xml] Is there a solution to have newline delimited output for xmllint ?
On 23/09/2018 15:12, gilles.que...@sputnick.fr wrote: This is the official libxml repository I guess(?). Yes. Do you know if a Debian package will be packaged ? I will contact Archlinux mainteners to update package, last update 2016. All distros will eventually catch up but it probably doesn't make much sense to ping maintainers before a new libxml2 version is released. Nick ___ xml mailing list, project page http://xmlsoft.org/ xml@gnome.org https://mail.gnome.org/mailman/listinfo/xml
Re: [xml] Is there a solution to have newline delimited output for xmllint ?
On 20/03/2018 16:45, Nick Wellnhofer wrote: This should be resolved now: https://gitlab.gnome.org/GNOME/libxml2/commit/da35eeae5b92b88d8ebdb64b4b327ac1c2cf1bce Nice, thanks. This is the official libxml repository I guess(?). Do you know if a Debian package will be packaged ? I will contact Archlinux mainteners to update package, last update 2016. Regards, Gilles Quenot ___ xml mailing list, project page http://xmlsoft.org/ xml@gnome.org https://mail.gnome.org/mailman/listinfo/xml
Re: [xml] Is there a solution to have newline delimited output for xmllint ?
On 20/03/2018 16:45, Nick Wellnhofer wrote: I agree that printing text nodes without a separator is rather useless and I always found it annoying that the output isn't terminated with a newline at all. In this case, I'm not too concerned about backward compatibility and I'd simply change the `--xpath` output to always print a newline after each node, text or not. This should be resolved now: https://gitlab.gnome.org/GNOME/libxml2/commit/da35eeae5b92b88d8ebdb64b4b327ac1c2cf1bce Also see the discussion here: https://gitlab.gnome.org/GNOME/libxml2/merge_requests/8 Nick ___ xml mailing list, project page http://xmlsoft.org/ xml@gnome.org https://mail.gnome.org/mailman/listinfo/xml
Re: [xml] Is there a solution to have newline delimited output for xmllint ?
https://github.com/sputnick-dev/xmllint ___ xml mailing list, project page http://xmlsoft.org/ xml@gnome.org https://mail.gnome.org/mailman/listinfo/xml
Re: [xml] Is there a solution to have newline delimited output for xmllint ?
My implementation of a wrapper command, named xmllint : ---8<-- #!/bin/bash # 2018-03-23 12:49:27.0 +0100 / Gilles Quenot# 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 ___ xml mailing list, project page http://xmlsoft.org/ xml@gnome.org https://mail.gnome.org/mailman/listinfo/xml
Re: [xml] Is there a solution to have newline delimited output for xmllint ?
In my mind, it would be a new switch, like --separator, that way, everyone can make his proper choice. And if the switch is new, there's no compatibility issue. (assuming is not that hard to fix the code). ___ xml mailing list, project page http://xmlsoft.org/ xml@gnome.org https://mail.gnome.org/mailman/listinfo/xml
Re: [xml] Is there a solution to have newline delimited output for xmllint ?
On 20/03/2018 14:14, gilles.que...@sputnick.fr wrote: I post many snippets with xmllint on stackoverflow and unix.stackexchange.com, but many times I'm stuck with this nice tool when it comes to retrieve N > 1 text node, because the output is not newline delimited (unlike xmlstarlet). It's not clear what exactly you're talking about, but I guess this is about the `--xpath` option and the bug you already posted: https://bugzilla.gnome.org/show_bug.cgi?id=740827 I agree that printing text nodes without a separator is rather useless and I always found it annoying that the output isn't terminated with a newline at all. In this case, I'm not too concerned about backward compatibility and I'd simply change the `--xpath` output to always print a newline after each node, text or not. But maybe other people want to weigh in. Nick ___ xml mailing list, project page http://xmlsoft.org/ xml@gnome.org https://mail.gnome.org/mailman/listinfo/xml