4 ms·
The first line of the file is just: <?xml version="1.0" encoding="UTF-8"?> The second line of the file contains 211792 characters of impenetrable XML. So, do
by kbenson 9y ago
The first line of the file is just:
<?xml version="1.0" encoding="UTF-8"?>
The second line of the file contains 211792 characters of impenetrable XML.
So, does no XML formatting tool exist to consume XML and pretty-print the output? I can tell you, as someone that consumes gigabytes of compressed JSON each day, having 500,000 plus characters of JSON on a single lines causes me no problems. The equivalent in XML should also cause any developer or tool wishing to consume it no problem, as this is a program interchange format, not a format meant to be read by a person (or why compress it anyway?). If someone is really espousing readability in document formats, maybe we should just replace opendocument with some variation of markdown?
Also, if your complaint is that XML is too obtuse because it's not formatted well, I'mnot sure how replacing it with a schema implemented in a RDBMS format is much better, especially when there are relatively few implementations of code that can read that format. Sure, everyone has bindings to SQLITE, but those are bindings to the same C library. Almost every non-toy programming language has had the DEFLATE algorithm implemented in it, and implementing a naive XML parser isn't hard (and I'm not sure anything beyond a naive XML parser is required for the OpenDocument format).
- fusiongyro 9y agoThe tool you're describing is `xmllint --format`.
- chris_wot 9y agoNotepad++ also has a lot of plugins.
- radicalbyte 9y agoThis, I use the XML and JSON pretty print plugins daily.
- oever 9y agoNot quite. `xmlint --format` can introduce unwanted spaces. Consider this example. <p><i>hello</i><b>!</b></p> `xmllint --format` adds a space between the 'o' and the '!'.
- pingiun 9y agoAFAIK this is only a problem with html
- fusiongyro 9y agoIs there a way to reformat XML without introducing space?
- kccqzy 9y agoI think so. Technically you can put linebreaks and whitespace within XML tags.
- the_mitsuhiko 9y agoIntroducing whitespace in most xml document formats changes the meaning.
- cjsuk 9y agoNo it doesn’t.
- majewsky 9y agoYou're both sort of correct. 1 and 2 below are equivalent (afaik), but 1 and 3 most certainly are not. 1: <x>an </x> 2: <x> an</x> 3: <x>a n</x>
- cjsuk 9y agoIt depends on your space settings in the DTD/schema/element. You can be explicit but very few people realise that.
- oever 9y agoIndeed. To indent properly you need to know the schema. The schema tells you to which element you may add or remove white-space.
- the_mitsuhiko 9y agoThat’s why I said most and not all. I did XML long enough to know both schemas and that their support is bad.
- deleted 9y ago[deleted]
- hasenj 9y ago> this is a program interchange format, not a format meant to be read by a person So why is it xml? I mean this defeats the whole point. Not to mention how it adds a lot of useless noise. If it's a program interchange format, it could at least be in binary.
- deno 9y agoThere exists binary XML. What OpenDocument uses is a plain text encoding of XML Infoset[1] (ordered tree of attributes and nodes with optional namespaces and external schema) data structure, but it can be encoded in many ways. You could encode XML infoset as JSON, which for example Google used to sort of do for their old “GData” APIs. (Actually that’s not true, because there’s no such thing as “plain text” so what OpenDocument uses really is a Unicode serialization of said data structure encoded as a (usually) UTF-8 binary stream with an ASCII variable length header directive specifying said encoding.) So why use XML Infoset? Unfortunately for certain qualities you might want in an open document interchange format there’s just nothing better. At any point in an XML Infoset document you can add additional namespaced attributes, nodes and even embed entire documents. For example an ODG document will include SVG elements. Any XML consumer should be able to parse and display a document produced by a completely independent program, and simply skip the parts it doesn’t support. If you were to design a clean slate data structure with similar qualities you would probably get something very similar to XML Infoset. Of course there is a lot of low hanging fruit and XML is by no means perfect. [1] https://en.wikipedia.org/wiki/XML_Information_Set https://en.wikipedia.org/wiki/XML_Information_Set
- hasenj 9y agoI find this hard to buy. Let's start with just one downside (which imo is the killer misfeature): startup time. According to the OP article you have to read the entire xml before you can do anything with it. Surely even if you weren't designing SQLite, it should be possible to design a binary format such that you can read relevant information quickly without loading and parsing the entire binary file.
- 9y ago
- deleted 9y ago[deleted]