Blacksmoke16 / oq

A performant, and portable jq wrapper to facilitate the consumption and output of formats other than JSON; using jq filters to transform the data.
https://blacksmoke16.github.io/oq/
MIT License
190 stars 15 forks source link

Add option to omit XML-declaration #14

Closed nichtich closed 5 years ago

nichtich commented 5 years ago

I almost created a pull request...

parser.on("--omit-xmldecl", "Omit XML declaration if converting to XML.") { processor.xml_decl = false }

but the crystal core library (XML::Builder) does not support omitting the XML declaration. Expected:

echo '{"x":1}' | ./bin/oq -o xml --omit-xmldec .
<root>
  <x>1</x>
</root>

The argument name could also be --no-xmldecl but in XSLT (a very verbose language) it is named omit-xml-declaration. Use case is creation of XML fragments, for instance of you loop over multiple input files with a shell script and combine the result in one XML document.

An possibly better alternative worth to consider is allowing to omit the XML root element for emitting XML fragments. This also requires possibility to omit XML declaration in XML::Builder:

echo '{"x":1}' | ./bin/oq -o xml --xml-root "" .
<x>1</x>
Blacksmoke16 commented 5 years ago

Currently working on some refactoring on how each format gets generated. It also would give us more control, such as being able to omit the dtd.