3 ms·
Does anyone know of a similar tool for XML? In particular, it would be cool to have a useful way to run xpath, and maybe xquery, from the command line. The tool
by edgarbob 12y ago
Does anyone know of a similar tool for XML? In particular, it would be cool to have a useful way to run xpath, and maybe xquery, from the command line. The tools I've found have unfortunate interfaces, e.g. they won't read XML from stdin.
- gav 12y agoHave you tried XMLStarlet[1]? It's my go-to for command line XML processing. [1] http://xmlstar.sourceforge.net/ http://xmlstar.sourceforge.net/
- unhammer 12y agoEven with libxml's xmllint you can do some xpath stuff: http://wiki.apertium.org/wiki/Xml_grep http://wiki.apertium.org/wiki/Xml_grep
- cgrubb 12y agoYou might check out these: http://www.w3.org/Tools/HTML-XML-utils/ http://www.w3.org/Tools/HTML-XML-utils/ However, I just use a Ruby script which loads the Nokogiri library: https://github.com/clarkgrubb/data-tools/blob/master/src/dom-awk.rb https://github.com/clarkgrubb/data-tools/blob/master/src/dom... https://github.com/clarkgrubb/data-tools/blob/master/doc/dom-awk.1.md https://github.com/clarkgrubb/data-tools/blob/master/doc/dom...
- jeroenjanssens 12y agoI'd just use xml2json and then apply jq. Usually gets the job done. The benefit of that is that you only need to learn jq. See this blog post I wrote a while ago for an example: http://jeroenjanssens.com/2013/09/19/seven-command-line-tools-for-data-science.html http://jeroenjanssens.com/2013/09/19/seven-command-line-tool...
- cryptonector 12y agoMost of the JSON conversions from XML get it all wrong though. XML is not really an object (dict, hash) based meta-schema. It's an array-based meta-schema. XML->JSON conversions should look something like this: [ {"tag":"something", "attributes": { ... }, "nodes": [ ...] }, ... ] with nodes being objects with one key to indicate if the node is a text node or an element, and if a text node then a value, and so on.
- bartc 12y agoxmllint - http://xmlsoft.org/xmllint.html http://xmlsoft.org/xmllint.html
- A_COMPUTER 12y agoI am not a huge fan of PHP, but you can do some useful stuff to XML using the PHP command line tool, provided you have the right libraries installed. I have run into situations where the package manager on a machine I'm using doesn't have an up to date xmlstartlet or xmllint, and have tidily gotten around this problem using PHP.