Am Montag, 21. Juni 2021, 14:59:54 MESZ hat Iwan Briquemont <tracnar@gmail.com> Folgendes geschrieben:
Hi,
BaseX works very well to do some quick queries or updates over files
(rather than using it as a DB).
I usually use the GUI for that but I think it could be quicker to have
a simple CLI tool for the terminal like sed to do things like:
Have a fancy XPath tool:
(-e is -q in basex)
echo "<root><ele>1</ele><ele>2</ele></root>" | basexsed -e 'root/ele'
1
2
Work over multiple documents quickly (somewhat equivalent to "for $path
in $args let $doc := doc($path) return xquery:eval($expr, map { '':
$doc})))
basexsed -e 'some/xquery' xmldocuments/*.xml
# Output the result
Allow multiple documents on stdin too, so you can chain expressions:
echo "<doc1/><doc2/><doc1/>' | basexsed -e 'doc1' | basexsed -e
'doc1/x'
Do updating expressions, by default outputting the changes:
basexsed -e 'delete node //n' xmldocuments/*.xml
# Outputs the docs without the n nodes
(-i is -u in basex)
basexsed -i -e 'delete node //n' xmldocuments/*.xml
# Changes the files in place
Automatically handle other formats like json, csv, html:
basexsed -e 'map:keys(.)' jsondocuments/*.json
# Outputs as json as well
AFAIK everything is already there in the basex command, so the main
change would be to support multiple files/documents in a streaming
fashion, and then a few smaller things like using stdin as the context-
item if no file is given and allowing the same arguments as in standard
tools like sed.
To make it nicer you could also add syntax highlighting to the console,
some shortcuts for longer XQuery parameters like serialization
indentation.
This would provide an alternative to tools like Xidel (
Is this something you would be interested in implementing? Or have some
people already done something similar?
Regards,
Iwan