News for hackers. Stuff that matters.
Re:XML is almost always misused by unilynx on Tuesday October 29, 2019 @05:11PM (#21392067)
XML is a actually wonderful format for data and especially extensible configuration if you combine it with XML Schema and CSS selectors...

- XML schemas give you a ready-to-use format to describe, restrict and document available configuration settings. The unique keys help and a libxml2 gives ready to use validation, even if you may need to 'translate' its error messages before showing them to end users

- XML schemas also support other annotations so you can further generalise your configuration readers by recording the necessary bindings in the XML schema itself, allowing to use it eg to define application user interfaces.

- Almost any text editor can do basic syntax validation preventing most typographic errors, and even better if they can read the schema

- XML schemas are extensible using <import>s, but namespaces still enforce some separation. You can define explicit points where plugins extend your configuration format using <any>

- Human editable - closing tags are noisy but more readable than }],{}] when non-programmers may have to edit these files just to add a few extra textfields to an UI.

- Better datatype support, eg datetimes, by using XML schemas. JSON's type support is too limited

- Support for comments!

- And once you've verified the schema... CSS selectors and DOM APIs to actually process the XML documents.

YAML fixed quite a few things, but still no date times or as far as I know standardised approaches to defining schemas. And I've lost count at how any attempts exist to add schema information or namespacing to JSON...

But for markup... we may be better off to just use markdown inside CDATA blocks

Re:XML is almost always misused by sedachv on Tuesday October 29, 2019 @05:23PM (#21392202)
> XML schemas give you a ready-to-use format to describe, restrict and document available configuration settings.

As someone that likes and uses s-expressions, I never thought I would find myself defending XML, but here we are in 2019, no one understands basic parsing theory anymore, and file formats have "evolved" to hot garbage like YAML and TOML.

XML has some great tools in comparison:

http://xmlsoft.org/xmllint.html https://relaxng.org/

> But for markup... we may be better off to just use markdown inside CDATA blocks

SGML can still make a comeback: https://leancrew.com/all-this/2014/09/sgml-nostalgia/

Re:XML is almost always misused by novok on Tuesday October 29, 2019 @05:29PM (#21392267)
YAML and TOML were optimized for human reading and writing, like markdown. XML & even JSON are not as human optimized, but still human usable.
Re:XML is almost always misused by sedachv on Tuesday October 29, 2019 @05:35PM (#21392326)
> YAML and TOML were optimized for human reading and writing, like markdown.

That was the rationalization, in reality I don't know what actual writing use case they were optimized for (Notepad?). XML in a syntax-aware editor with the help of automatic schema validation makes it far easier to write than YAML or TOML.

Re:XML is almost always misused by novok on Tuesday October 29, 2019 @06:10PM (#21392641)
I don't need a special editor to write out YAML (if it didn't have tab dependence) or TOML quickly. It's also a lot faster for a human to read vs XML. JSON is fairly readable, but a bit of a pain to write out compared to ini files, since you have to quote all strings.

If your going into complicated things like schemas or other complicated structures, then you probably shouldn't be using YAML or TOML. I would mostly use it for config or other simple things.

At this point if you are not interacting with 20 year old java software, that was created when JSON didn't exist and XML was king, you should be using TOML for simple config, JSON for most things and heavyweight XML, protobuf or csv for the specialized cases. And while we are at it, markdown for simple documentation.

Even gradle decided to use groovy scripts as their config language because it's far more human readable and usable.

Re:XML is almost always misused by sedachv on Tuesday October 29, 2019 @09:07PM (#21393713)
> At this point if you are not interacting with 20 year old java software, that was created when JSON didn't exist and XML was king, you should be using TOML for simple config, JSON for most things and heavyweight XML, protobuf or csv for the specialized cases.

You should be using S-expressions.

Re:XML is almost always misused by gambler on Tuesday October 29, 2019 @05:37PM (#21392350)
Humans should not interact with computers by manually editing data structures serialized to ASCII.
Re:XML is almost always misused by vinceguidry on Tuesday October 29, 2019 @05:42PM (#21392397)
The alternatives are usually worse.
Re:XML is almost always misused by unilynx on Tuesday October 29, 2019 @05:43PM (#21392398)
But we can't always budget a nice configuration application.

And once we've just put simple XML file there for configuration and we're past the prototyping phase... "well this actually works good enough, let it be".

Re:XML is almost always misused by Const-me on Tuesday October 29, 2019 @06:55PM (#21392970)
You likely need data model classes for the config anyway, along with support of serialization and deserialization (XML or not is not important). Use a stock property grid control, pass the root object of the config, and you’ll get a GUI that does the job much better than ASCII files.
Re:XML is almost always misused by tannhaeuser on Tuesday October 29, 2019 @06:03PM (#21392579)
> SGML can still make a comeback

Hey, you should checkout http://sgmljs.net (my project).

Re:XML is almost always misused by sedachv on Tuesday October 29, 2019 @09:25PM (#21393800)
Very cool!
Re:XML is almost always misused by scott_s on Tuesday October 29, 2019 @05:39PM (#21392370)
I agree. The author and other commenters here have not proposed an alternative which provides two features I consider critical to a generic data format: schema specification and validation; and easy parsing support in many ecosystems. JSON and Yaml don't seem to have mature, widely adopted schema specification and validation. And I'm not aware of anything outside of XML, JSON and Yaml which have such wide parsing support in so many different ecosystems.
Re:XML is almost always misused by theamk on Tuesday October 29, 2019 @10:09PM (#21394035)
JsonSchema is pretty good -- it is not as widely used as XSD, but it has libraries for most languages.

And of course JSON is the easiest thing to parse in scripting languages, like Python and Ruby -- the entire API is one line, and then you have a native structure you can work with.

Re:XML is almost always misused by spiralx on Friday November 01, 2019 @11:38AM (#21419942)
> JsonSchema is pretty good -- it is not as widely used as XSD, but it has libraries for most languages.

It's okay now that the newest revisions support more realistic use cases, but ironically I find it impossible to write as JSON... I write them as YAML which my validator supports natively :)

It's still not as nice as RELAX-NG's compact schema format though IMO :)

https://relaxng.org/compact-tutorial-20030326.html

And the LXML library for Python was a pleasure to use compared to any other similar library I've used.

Re:XML is almost always misused by tannhaeuser on Tuesday October 29, 2019 @06:24PM (#21392760)
> But for markup... we may be better off to just use markdown inside CDATA blocks

No we arent't. markdown itself is literally specified as a shortform of HTML [1], and can be translated into canonical angle-bracket syntax using SGML short references (though not completely eg. markdown reference links require unlimited forward lookup). This gives a canonical representation of markdown in SGML/XML even if you don't use SGML.

[1]: https://daringfireball.net/projects/markdown/