Requested features for --shell mode
When I use the --shell
option, I would like to be able to delete a node (deleting everything below that node). Using the write
command I can save a node to a different file, but it would be useful to have the ability to trim a branch of the XML file. And another feature could be to load an external file under a node, as a kind of pruning and grafting, to add additional information under a node.
I would like to use commands under --shell
that would return "clean" results. For example, when I run the following command line
oscar@toreyes-i7:/tmp$ echo "whereis //url" | xmllint --shell /mnt/filer/html/produccion/datos/diarioas/apuestas/2019/05/29/videos/1559132834_298371.xml
/ > /news/tags/tag1/url
/noticia/tags/tag2/url
/noticia/tags/tag18/url
/news/authors/author1/url
/noticia/objetosmedia/noticia/videos/video1/agrupaciones/agrupacion1/url
/noticia/objetosmedia/noticia/videos/video1/agrupaciones/agrupacion2/url
/noticia/objetosmedia/noticia/objetosmedia/noticia/videos/video1/agrupaciones/agrupacion3/url
/ > oscar@toreyes-i7:/tmp$
the response contains the substring / >
twice, corresponding to the interactive prompt, mixed with the actual results.
I think it would be interesting to have a parameter to pass the commands to be executed under --shell
, that does not show the prompt in the response, and that allows to chain several commands.
In this way xmllint could be used as a tool for editing XML files a little more powerful and with better ability to automate the execution of commands. My idea would be able to exectute something like this:
xmllint --noprompt --shell --commands "cd /news/authors/authors; write /tmp/deleted_node.xml.bak; delete . ; loadnode /tmp/new_value.xml; write"/mnt/filer/html/production/data/journals/betting/2019/05/29/videos
That string of commands would switch to a certain node in the XML, save it to an external file (as a backup of what we are going to delete), delete the current node, load the contents of an xml file at that position and save the modified file.
I also find it interesting, as an advanced version of this, that the commands can be specified from a file, for example by means of a --commandfile option.
The final syntax of the command string, or the names of the commands and the parameters of each one are up to you :-)