News for hackers. Stuff that matters.
Re:A Brief Defense of XML by Devasta on Friday January 06, 2023 @07:42AM (#34274028)
<star

    bayerName="Beta Pictoris"

    spectralType="A6V"

    mass="1.75" 

    luminosity="8.7">

    <position 

        rightAscension="05h 47m 17.1s" 

        declination="−51°03′59&quot;"

        distance="63.4ly"/>

    <age min="20My" max="24My"/>
</star>

The tag-content ratio of XML is only as bad as you make it.

Re:A Brief Defense of XML by tacone on Friday January 06, 2023 @09:00AM (#34274597)
Of course. The problem with that approach is that every value becomes a string with no hint about which type it should be converted to. In comparison JSON has - at least - basic types.
Re:A Brief Defense of XML by __afk__ on Friday January 06, 2023 @09:35AM (#34275001)
There are more ways to type (at schema and inline) and more types (see the common XSD types) available OOB in XML than JSON could ever have. Then we can introduce custom types. JSON looks rather impoverished in comparison.
Re:A Brief Defense of XML by mattpallissard on Friday January 06, 2023 @09:56AM (#34275276)
Many people "love yaml" and "hate XML" but never dealt with XSD, so they don't even realize what they're talking about syntax instead of functionality.

Admittedly, XML isn't the most pleasant syntax to interact with by hand.

Re:A Brief Defense of XML by Devasta on Friday January 06, 2023 @12:00PM (#34277318)
XML syntax is fine so long as you're using a proper IDE. I manage a team of reporting analysts and all of them come from Business Analyst or Accountancy backgrounds; they write and maintain XSLT transforms just fine, once they spend a day or two getting used to IntelliJ IDEA.
Re:A Brief Defense of XML by crispyambulance on Friday January 06, 2023 @08:15PM (#34283909)
XML was a great idea. At some point in the early naughts, however, XML-abuse became rampant-- too many crappy tools, too many half-assed attempts at putting square pegs into round holes. It didn't help that XML got inextricably associated with those horrible over-complicated ws-* standards that ended up sending Russian novel-sized "hello world" information exchanges.

The main idea, however, was wonderful. An information exchange format (xml itself), a way to define schemas (xsd), a transformation language (xslt), and stylesheets (xsl?). I kind of miss it.

Re:A Brief Defense of XML by dragonwriter on Friday January 06, 2023 @09:36PM (#34284508)
XSL (Extensible Stylesheet Language) the stylesheet part, it included XSLT (transform), XPath, and XSL-FO (XSL Format Objects).

XSLT and XPath each went on to great solo careers, XSL-FO kind of fizzled when XML+XSL failed to displace HTML+CSS.

Re:A Brief Defense of XML by spiralx on Saturday January 07, 2023 @10:37AM (#34288963)
XSL:FO is great for turning into PDFs though.

There's also XQuery for transformations and XSD/RelaxNG for schemas, the whole combination of XML database, WYSIWYG (via XSLT) XML editor and output transformations is very powerful, every journal we published and every site we ran at the British Medical Journal was generated that way.

Re:A Brief Defense of XML by giantrobot on Friday January 06, 2023 @10:00PM (#34284669)
I miss XSLT every time I see megabytes of JavaScript converting some JSON into a soup of HTML to display in browsers. A bunch of JavaScript with a bunch of overwrought "components" is serving as a very complicated templating system.

A lot of really stupid JavaScript could be done fairly easily with XSLT natively inside a browser engine. An XML document can point to its own XSL(s) so get rendered to the appropriate delivery format or just used directly as data.

Re:A Brief Defense of XML by phoehne on Friday January 06, 2023 @10:35PM (#34284882)
I don't miss it. I had several projects where it seemed like a good idea. I pushed it as a good idea. I really wanted it to work. Some developers (usually the sharper bulbs) got it. A lot of developers really struggled with it. Especially the folks who were 'front end' developers. Even in the 2000's, when everything was trying to go XML, staffing those roles was hard.
Re:A Brief Defense of XML by giantrobot on Friday January 06, 2023 @11:22PM (#34285167)
Tooling was XSLT's Achilles heel. Too many tools had no or poor XSLT support. What's confusing to me is a lot of the JavaScript templating today has equally bad tooling yet everyone's in love with it.
Re:A Brief Defense of XML by waldir on Saturday January 07, 2023 @07:54AM (#34287605)
Doesn't that suggest that tooling wasn't the issue after all?
Re:A Brief Defense of XML by giantrobot on Saturday January 07, 2023 @03:19PM (#34292266)
The lack of tooling for XSLT and modern JavaScript stuff are on different sides of the adoption curve. XSLT lacked tooling on the upside of the curve so it never hit critical mass. Its other problems could have been solved had it hit critical mass and seen wider adoption.
Re:A Brief Defense of XML by dragonwriter on Friday January 06, 2023 @09:28PM (#34284450)
> Many people "love yaml" and "hate XML" but never dealt with XSD, so they don't even realize what they're talking about syntax instead of functionality.

No, I'm pretty sure that if they have only used XML syntax as a data rep and not XML-associated tooling like XSD, they are quite aware that when thet say they hate XML they are talking about syntax.

OTOH. I am surprised at the number of people that seem to thing “has a schema language that can be used to specify structure beyond just the basic raw language” distinguishes XML from other data representation languages.

Or, more generally, the way that “if you don’t like XML, maybe your problem is you aren’t using enough of it” has become an edgy contrarian position rather than steretypical establishment enterprise consultant thing it was 15 or so years ago.

Re:A Brief Defense of XML by zozbot234 on Friday January 06, 2023 @08:17PM (#34283920)
JSON-LD can express any RDF datatype, and some XSD types (though not all) have standardized matches in RDF.
Re:A Brief Defense of XML by electroly on Friday January 06, 2023 @10:23AM (#34275639)
The quotes in XML don't make it a string; in the XML schema you can specify the type (and so much more). JSON has a lot of benefits but it absolutely loses this particular comparison. XML schemas will give you all the type information and automatic validation you can swallow. Typing in XML is far richer than in JSON. There's even a date type!
Re:A Brief Defense of XML by smitty1e on Friday January 06, 2023 @07:58PM (#34283749)
You mean an .xsd?

JSON has .avro, I thought.

It's all data. Validation logic is sold separately.

Re:A Brief Defense of XML by dragonwriter on Friday January 06, 2023 @08:06PM (#34283833)
> The quotes in XML don’t make it a string; in the XML schema you can specify the type (and so much more). JSON has a lot of benefits but it absolutely loses this particular comparison.

JSON, like XML, has several schema languages, which have widely-available libraries for generating host language typings, validation, etc.

> Typing in XML is far richer than in JSON. There’s even a date type!

JSON Type Definition has timestamp, JSON Schema has date, date-time, time, and duration.

Re:A Brief Defense of XML by int_19h on Friday January 06, 2023 @08:49PM (#34284155)
The nice thing about XML being an extensible markup language is that schemas (and metadata like xsi:type) could be easily written inline, making the document fully self-contained.
Re:A Brief Defense of XML by mdaniel on Saturday January 07, 2023 @02:11PM (#34291494)
I haven't personally tried such a stunt, but I'd bet it's possible to do that with JSON Schema, too, if the schema resolver tolerates the same self-references style in `$schema`. My experience with the tooling is "lol, yeah right" but shrug seems reasonable

    {
      "$schema": "#/$theSchema",
      "$theSchema": {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "$id": "MySchema",
        "type": "object",
        "properties": {
          "productId": {
            "description": "The unique identifier for a product",
            "type": "integer"
          },
          "productName": {
            "description": "Name of the product",
            "type": "string"
          },
          "price": {
            "description": "The price of the product",
            "type": "number",
            "exclusiveMinimum": 0
          }
        }
      },
      "productId": 1,
      "productName": "An ice sculpture",
      "price": 12.50
    }
Re:A Brief Defense of XML by WorldMaker on Friday January 06, 2023 @08:13PM (#34283895)
JSON Schemas exist too. The most common being the eponymously named type: https://json-schema.org/

I've seen JSON schemas describe things like date types and plenty more. If you are including schema metadata alongside XML, then for a fair fight you can include JSON schemas, too.

Re:A Brief Defense of XML by stcroixx on Friday January 06, 2023 @01:39PM (#34278952)
You've got to learn XML and XSD first, then you'll see that's not what you're looking at at all.
Re:A Brief Defense of XML by Koshkin on Friday January 06, 2023 @01:29PM (#34278803)
You mean "markup" vs. "content." At least, such was the original intent: you store what is considered data as content, and metadata of any sort as markup. In many use cases, however, this distinction is now ignored or simply non-existent. One other "abuse" of XML as a structured representation of data is to embed a "foreign" (i.e. non-XML) syntax, like in the above example of rightAscension (which is not the worst example, to be fair).
Re:A Brief Defense of XML by ahepp on Friday January 06, 2023 @07:50PM (#34283658)
I often feel confused about when to use tags and when to use attributes. Is there principled guidance on this?
Re:A Brief Defense of XML by chipsa on Friday January 06, 2023 @08:35PM (#34284052)
No? But I think that if you have substructure, like a position or can reasonably have multiples of the thing, it should be a tag.
Re:A Brief Defense of XML by epalm on Friday January 06, 2023 @08:19PM (#34283941)
I generally try to reserve attributes for metadata. That is, data about the data contained in the tag.
Re:A Brief Defense of XML by int_19h on Friday January 06, 2023 @08:47PM (#34284150)
There is none. In general, the main difference is that elements are all ordered wrt each other, while attributes are not. This ought to make the choice simple, except that attributes also cannot contain nested data structures.

A particularly unusual take is to ignore the difference and allow either attributes or child elements as different ways to do the same thing. This is what XAML does; e.g. this:

   <Button Content="Foo" />
is identical to:

   <Button>
       <Button.Content>Foo</Button.Content>
   </Button>
Re:A Brief Defense of XML by dwaite on Friday January 06, 2023 @08:55PM (#34284199)
There is for user-viewable markup-enhanced documents, like SVG and HTML - which is pretty much what you experience with SVG and HTML authorship by hand.

If data should be presented to the user by a user agent that doesn't understand extensions to the markup, it should be using text nodes.

If it is a modification to a subset of a block of text, such as emphasizing a word, it should be a new element.

If it is a block of semantic metadata, you would structure that as a hierarchy of elements with attributes.

Otherwise, it is usually an attribute on an existing element.

SVG is a bit of a zany format in XML because so much of the content is points or encoded data, which get stuffed in some truly epic attributes.

XML wasn't really made for pure data formats, even though shoehorning that in was the majority of the market's effort.

Re:A Brief Defense of XML by magicalhippo on Friday January 06, 2023 @10:14PM (#34284763)
I'd say if it's for general data exchange, I'd shy away from attributes as much as possible. Not all tools handle them well, and XML novices can get confused about their usage.

Using plain tags is so obvious that just about anyone can get it, and in my experience there's no real advantage to using attributes.

At least that's my experience at work, where we use XML as our primary integration format for others that want to deliver data to our system. When going through with a new customer, the few attributes we have almost always cause some kind of issue or misunderstanding.

Re:A Brief Defense of XML by somat on Friday January 06, 2023 @08:36PM (#34284067)
I think that if you are encoding data, like your example, you should not use attributes, attributes are best used when you are using xml in it's text markup role.

In the text markup role tags are like functions and the attributes are parameters to the functions. but in the data encoding role the attributes are another redundant key value store and you end up with a confusing mix where some of your kv's are in the tag and some are in the attributes and it is a bit of a mess.

Re:A Brief Defense of XML by kijin on Friday January 06, 2023 @08:42PM (#34284109)
In the parent's example, every value is in the attributes. Tags only serve as objects that contain those values, and never have "content" of their own. This style might not have been the original intent of XML, but at least it's consistent and easily readable.
Re:A Brief Defense of XML by somat on Friday January 06, 2023 @08:52PM (#34284178)
The parent example was remarkably consistent, far from the worst I have seen however...

There is a star tag(presumably a list of star tags) each of which contains a single position tag. The star tag is is full of attributes, and the position tag is full of attributes, now you have a complicated(not that complicated, hyperbola is for arguments sake) access method where you need to do different things based on what data you want out of the structure. Why was the position tag not an attribute? What happens when you want to encode the rightAscension, and declination, they will get their own tag, in fact they probably just should have tagged everything in the first place and avoided attributes.

Re:A Brief Defense of XML by klysm on Friday January 06, 2023 @09:03PM (#34284251)
I still find closing tags redundant.
Re:A Brief Defense of XML by chrismorgan on Friday January 06, 2023 @09:38PM (#34284521)
If going in this direction, I’d want justification for position and age still being separate elements. Elements are clearly suitable or necessary when you want multiple values, order-sensitivity, or to contain something other than a single text value. But that’s not the case here, and I find “hierarchical structure” or “property grouping” to be weak justification.

So then:

  <star
    bayerName="Beta Pictoris"
    spectralType="A6V"
    mass="1.75"
    luminosity="8.7"
    rightAscension="05h 47m 17.1s"
    declination="−51°03′59″"
    distance="63.4ly"
    minAge="20My"
    maxAge="24My"/>
We are, of course, playing into the article’s second footnote here.

(Also: I’m curious why you turned the original document’s ″ (U+2033 DOUBLE PRIME) into &quot; (", U+0022 QUOTATION MARK).)

Re:A Brief Defense of XML by sixbrx on Saturday January 07, 2023 @09:36AM (#34288303)
Position really needs an "epoch" metadata attribute (coords are relative to the equinox which moves over the years) so the coords need the "epoch" to be specified (e.g. "2000" or "2050"). That this kind of thing can rear its head unexpectedly might be an argument for favoring separate elements to group fields? If it were thrown in with the other attributes of "star" it looks like it qualifies the star, but it only really qualifies the coordinates.
Re:A Brief Defense of XML by Devasta on Saturday January 07, 2023 @01:26PM (#34290957)
I changed the character because I'm a dumbass who thought I was looking at a quotation mark.

I don't ever see double prime at my job, so it was probably muscle memory.