3 ms·
From examples, this is only like jq in the sense that the q stands for the same thing. Even the way it does that is different. An xmlq that was really like jq
by hyperpallium2 5y ago
From examples, this is only like jq in the sense that the q stands for the same thing. Even the way it does that is different.
An xmlq that was really like jq would be fun, about 20 years ago.
- cerved 5y agoI would still like xmlq, there are (regrettably) still a lot of applications that store data and configuration in xml
- dotancohen 5y agoThere is `xq` today, which parses XML like `jq`. I think that it is relatively unknown because it is part of the `yq` package for parsing YMAL. So just install `yq` via PIP and you'll get `xq` as well. There is also `xmlstarlet` for parsing XML in a similar fashion.
- jle17 5y agoJust looked into this and I think it's worth mentioning that there are two different projects called `yq`. The first one that came up (written in go instead of python) is not the right one and doesn't have the `xq` tool.
- hyperpallium2 5y agoxmlstarlet is really nothing like jq, as a language. But yes, I use it because it is the best commandline xml processor I'd found. That's the only similarity to jq. Is this the yq? https://kislyuk.github.io/yq/ https://kislyuk.github.io/yq/ It does contain an 'xq', as a literal wrapper for jq, piping output into it after transcoding XML to JSON using xmltodict https://github.com/martinblech/xmltodict https://github.com/martinblech/xmltodict (which explodes xml into separate JSON data structures). This is a bash one-liner! But TBF it really is a 'jq for xml'. I think it would be horrible for some things, but you could also do a lot of useful things painlessly.
- dotancohen 5y agoThank you for the comments. I've only recently discovered both tools, and literally used them once each. Of the two `xq` was easier for my particular work case (parsing a Magento config) but I keep both tools in my virtual toolbox. If you have any other suggestions for parsing XML for exploratory purposes I'm very happy to hear them.
- hyperpallium2 5y agoThanks! Not actually a reccommendation, but I have used xsltproc (command line xslt), but it is horrible to use because xslt syntax is horrible (though xslt's concepts are pretty cool). One thing is it enables you to use XPath in all its glory. Just installed xq. It's nice just seeing the pretty-printed json output, so thanks for the pointer. Probably better than xmlstarlet for my usage, which just queries and outputs text, not xml. hmmm, that's probably true for most commandline uses...