News for hackers. Stuff that matters.
Re:How to Avoid Being Called a Bozo When Producing XML (2005) by cptskippy on Sunday July 31, 2016 @10:16AM (#12197041)
XML is well regarded in the enterprise and languages like JAVA, C#, and VB.NET handle is spectacularly as an exchange format.

I think it's bad reputation comes from anyone not using an enterprise language because the support just isn't there.

I recall working with a partner who we were doing an identity federation with. Our system was using WS-Trust which is a SOAP/XML protocol. It wasn't ideal but everyone seemed to support it ok. These guys were cutting edge though and used Ruby on Rails.

No support for the protocol wasn't a huge deal, just means you have to craft your XML for your SOAP calls yourself. But at the time we were doing this, RoR didn't have SOAP or XML libraries. They had to write everything from the ground up. It sucked for me and I was just fielding rudimentary questions, I can't imagine how painful it must have been for them.

Re:How to Avoid Being Called a Bozo When Producing XML (2005) by wtbob on Sunday July 31, 2016 @11:03AM (#12197251)
> I think it's bad reputation comes from anyone not using an enterprise language because the support just isn't there.

On the contrary, I think that XML's bad reputation comes from the fact that it is <adverbial-particle modifies="#123">so</adverbial-particle> <adverb id="123">incredibly</adverb> <adjective>verbose</adjective>.

Also, the whole child/attribute dichotomy is a huge, huge mistake. I've been recently dealing with the XDG Menu Specification, and it contains a child/attribute design failure, one which would have been far less likely in a less-arcane format.

XML is not bad at making markup languages (and indeed, in those languages attributes make sense); it is poor at making data-transfer languages.

JSON has become popular because a lot of bad programmers saw nothing wrong with calling eval on untrusted input (before JSON.parse was available). It's still more verbose than a data transfer format should be, and people default to using unordered hashes instead of ordered key-value pairs, so it's not ideal.

The best human-readable data transfer format is probably canonical S-expressions; the best binary format would probably be ASN.1, were it not so incredibly arcane. As it is, maybe protobufs are a good binary compromise?

Re:How to Avoid Being Called a Bozo When Producing XML (2005) by 616c on Sunday July 31, 2016 @02:01PM (#12198005)
I think the worst of this is what I call semantic incoherence.

I have a system that has things like <Task ID="6">Blah</Task>. Why is the ID, clearly always an integer in every sample of hundreds I see, represented as a string?

Another favorite: <ExecuteCommand>[CDATA[Batchfile.bat]]</ExecuteCommand>, while a binary or something else will be <ExecuteCommand>"program.exe /argument:f /argument2:x"</ExecuteCommand>.

By the way, this is an enterprise as it gets: a software tool from a four-letter hardware company, quite huge, trying to sell off its software division. I wonder why.

XML is like all other "crap" tools: Java, PHP, SOAP: some people do not grok the spirit of the law, and they do weird things that reflect their discomfort and hurried need to operate with it. Many write it off.

I agree with your points, this is just my corrolary. The sad thing is SEXPR and XML are not far removed, one is arguably a subset of the other, and notice how people lose their shit when you ask them to consider Lisp languages for daily works because "all those parens are stupid" and how the culture surrounding a potentially viable tools makes people close up without delving in with curiosity.

https://en.wikipedia.org/wiki/SXML

http://arclanguage.org/item?id=19453

Re:How to Avoid Being Called a Bozo When Producing XML (2005) by ams6110 on Sunday July 31, 2016 @02:19PM (#12198104)
> Why is the ID, clearly always an integer in every sample of hundreds I see, represented as a string

Becase XML is a text-based markup. If you truly want binary data you need to encode it and use CDATA sections.

Re:How to Avoid Being Called a Bozo When Producing XML (2005) by 616c on Sunday July 31, 2016 @02:24PM (#12198131)
That was not quite my point.

Why pretend it is a string at all?

<Task> <ID>3</ID> </Task>

I should have been more clear. Sometimes you have these argument type deals <Task ID="3"> where I would at least hope for <Task ID=3> or the monstrosity above (I assume ID=3 is not valid in hindsight, I am getting tired just writing this all on the second pass even!). And I see all different variations in the same XML file! There is no logical consistency, not even in the same config for the same function of this multi-stage system.

I am not even a novice programmer, and I find the variation annoying, and sometimes hard to reason about when I want to know what the hell the programer was thinking.

The valid part for the CDATA portion has changed several times in minor releases, so when our server team upgrades, I get to figure out the new syntax.

I thought XML was proposed to avoid these things! Haha. Again, tools in the hands of "wise men" like me are dangerous. I am probably as ignorant as them, I just think I know better!

Re:How to Avoid Being Called a Bozo When Producing XML (2005) by oceanswave on Sunday July 31, 2016 @03:27PM (#12198436)
Enclosing the attribute within double quotes isn't pre-disposing the value to be of a particular type. It's part of the XML spec that attribute values are contained within double quotes, and must be to be valid. The type isn't implied in the file.

An xml schema such as <xs:element name="Task"> <xs:complexType> <xs:attribute name="ID" type="xs:int" use="required" /> </xs:complexType> </xs:element>

could more explicitly declare the type of the value.

Re:How to Avoid Being Called a Bozo When Producing XML (2005) by 616c on Sunday July 31, 2016 @04:02PM (#12198574)
Thanks for the explanation. I guess in this case I learned be careful what you wish for. I guess this is why I prefer the

<Item> <Parameter><Data></Parameter> </Item>

But this is my ignorance of XML and familiarity with HTML showing.

Re:How to Avoid Being Called a Bozo When Producing XML (2005) by ams6110 on Sunday July 31, 2016 @02:51PM (#12198279)
XML as a config file format was a disaster in every example I ever encountered. Config files are supposed to be editable by humans using editors, and most that I saw were too complex for that. In particular the NeXT/Apple property file formats are horrible abuses of XML.

As a format to represent structured data, it could be fine as long as you were pragmatic about it. In the case of <task id="3"> you either assumed that "id" was always an integer or you validated it with a schema declaration, which quickly got hairy.

In practice I never validated XML beyond it being well-formed (which was provided by default in any parser) and never had any real problems.

Re:How to Avoid Being Called a Bozo When Producing XML (2005) by thangalin on Sunday July 31, 2016 @02:53PM (#12198294)
What takes fewer lines of code to parse?

    <element.name id.value="3.14">
Or accepting both:

    <element.name id.value="3.14">
    <element.name id.value=3.14>
How would you specify an empty value for mandatory attributes?
Re:How to Avoid Being Called a Bozo When Producing XML (2005) by colejohnson66 on Sunday July 31, 2016 @03:12PM (#12198372)
I've seen empty values written as

    <tag attr1 attr2="val">data</tag>
Whether that's legal or not, I don't know.
Re:How to Avoid Being Called a Bozo When Producing XML (2005) by oceanswave on Sunday July 31, 2016 @03:28PM (#12198447)
not valid. wondering if you've seen that within HTML, where it is valid.
Re:How to Avoid Being Called a Bozo When Producing XML (2005) by colejohnson66 on Sunday July 31, 2016 @04:42PM (#12198741)
Actually, now that you mention it, I think it's from Chrome's Inspect Element tool, but I can't check right now.

I think if you wrote something like

    <div class="">...</div>
it would display in the tool as

    <div class>...</div>
Re:How to Avoid Being Called a Bozo When Producing XML (2005) by kozak on Monday August 01, 2016 @07:15AM (#12201516)
Chrome's Inspect Element shows you the non-serialized DOM structure, which means it's neither XML nor HTML at that point.
Re:How to Avoid Being Called a Bozo When Producing XML (2005) by chiph on Sunday July 31, 2016 @02:51PM (#12198280)
Oh, this is the difference between attribute-oriented XML, element-oriented XML, and whatever-the-hell-we-feel-like-oriented XML. Publishers should pick one of the first two and be consistent about it.
Re:How to Avoid Being Called a Bozo When Producing XML (2005) by ams6110 on Sunday July 31, 2016 @03:00PM (#12198322)
Agree. Practical/pragmatic use of XML as a data format requires consistency.
Re:How to Avoid Being Called a Bozo When Producing XML (2005) by CamperBob2 on Sunday July 31, 2016 @04:03PM (#12198579)
I have a system that has things like <Task ID="6">Blah</Task>. Why is the ID, clearly always an integer in every sample of hundreds I see, represented as a string?

You're really asking a different question here: "Why should an integer be used as a task ID?" Storing the task ID as a string may give you options in the future that you wouldn't otherwise have, at a relatively small cost in parsing performance and validation overhead.

Most of the world's regrettable XML schemas were faulty at the specification stage, not the implementation stage. To minimize the likelihood of eventual regret, I usually prefer to store stuff in strings unless there's a very good reason not to. The fact that I'm using XML means that I'm not that concerned about performance, so... strings, it is.

A similar argument can be applied to the child/attribute dilemma. If there's even the slightest chance that a field isn't always going to be a leaf node, I'll do the extra typing and make it a child. Ideally the parser would be written to make them both work the same anyway.

Re:How to Avoid Being Called a Bozo When Producing XML (2005) by 616c on Monday August 01, 2016 @01:31PM (#12204271)
I see were you were downvoted, but I happen to see merit with your comment. Again, a lot of people make technical decisions without stepping back and just scanning their choices as non-specialist (in the context of their programming domain) and ask hey, does this make sense?
Re:How to Avoid Being Called a Bozo When Producing XML (2005) by CamperBob2 on Monday August 01, 2016 @05:28PM (#12206163)
Technically all attributes are supposed to be surrounded by quotes regardless of how they're interpreted. That renders the premise of my whole comment invalid, to be "technically correct," so the people downvoting may have had that in mind.

Still, there are plenty of XML applications that leave out the quotes on numeric attributes. My point was really that they're not doing themselves any favors by abusing the spec that way. A text-based markup language is a great example of how premature optimization is unhelpful most of the time.

Re:How to Avoid Being Called a Bozo When Producing XML (2005) by FunnyLookinHat on Sunday July 31, 2016 @12:23PM (#12197561)
> JSON has become popular because a lot of bad programmers saw nothing wrong with calling eval on untrusted input (before JSON.parse was available).

Disagree. JSON became popular because it was extremely easy to implement (both for marshaling and consuming), and because it was extremely lightweight.

I think you could also make the argument that JSON was conceptually easier for programmers to wrap their minds around. You could just pretty-print it and quickly get an idea for the object's format, attributes, etc.

Re:How to Avoid Being Called a Bozo When Producing XML (2005) by seagreen on Sunday July 31, 2016 @02:32PM (#12198177)
I agree, especially with the easy to understand part.

Look how short the standard is: http://www.ecma-international.org/publications/files/ECMA-ST... It's small and perfect, like a 2x1 LEGO block.

Here's the XML spec: https://www.w3.org/TR/REC-xml/ <backs away slowly>

Re:How to Avoid Being Called a Bozo When Producing XML (2005) by ams6110 on Sunday July 31, 2016 @02:23PM (#12198126)
XML could be fairly lightweight also. It was all the enterprisey-standard formats that were hideous.

E.g.

    {"name":"John","age":42}
vs.

    <person name="John" age="42" />
Re:How to Avoid Being Called a Bozo When Producing XML (2005) by rimantas on Sunday July 31, 2016 @02:33PM (#12198180)
Now do the nested objects in both. One line does not show much.
Re:How to Avoid Being Called a Bozo When Producing XML (2005) by Mikhail_Edoshin on Monday August 01, 2016 @07:10AM (#12201497)

    <person id="123" name="John" age="42" sec:checksum="...">
      <family-member type="spouse" ref="456""/>
      <family-member type="child" ref="789" />
      <fin:credit-rating score="A"
          last-change="2016-02-04T12:34:56Z" />
      <уфмс:статус значение="42" />
    </person>
Here we can describe `person/@id` as element ID and `family-member/@ref` as a reference to an ID so our XML tools can link these together.

Also note three more elements from different namespaces: `@sec:checksum` could be some kind of technical information about the record, `fin:credit-rating` is added by the finanical module. The `@last-change` is defined as datetime so as we read it with other XML tools we'll get it as datetime type.

The next one is a tag in Russian language that describes something related to Russia; XML can use the whole Unicode in tag and attribute names.

Also, XML names are globally unique by design so there's no clash between all the different pieces and the tools can easily be configured to ignore parts they don't understand or work as a glue between different areas.

We can still efficiently validate the syntax the whole piece or parts of it as we see fit.

Re:How to Avoid Being Called a Bozo When Producing XML (2005) by wtbob on Sunday July 31, 2016 @04:07PM (#12198595)
> Disagree. JSON became popular because it was extremely easy to implement (both for marshaling and consuming), and because it was extremely lightweight.

A canonical S-expression parser is strictly easier to implement, given that S-expressions consist only of lists and byte sequences (no numbers or objects), and is even more lightweight. JSON's big advantage was that it was familiar to a JavaScript programmer, that's all.

Re:How to Avoid Being Called a Bozo When Producing XML (2005) by auganov on Sunday July 31, 2016 @02:10PM (#12198063)
S-expressions is basically no syntax. Human-readability depends solely on the person that comes up with the schema. I mean there's many reasons to love S-expressions but human-readability is an unusual one. edn [0] is an interesting compromise (as is clojure).

XML is actually IMO not that bad at human readability, it's pretty good. It's terrible at human writability. Conversely S-exps are lovely to work with.

[0] https://github.com/edn-format/edn

Re:How to Avoid Being Called a Bozo When Producing XML (2005) by MichaelGG on Sunday July 31, 2016 @03:25PM (#12198433)
XML's bad rep for verbosity is almost entirely due to the nonsensical, terrible idea of requiring names in the end tag. Without that, it's about the same level of verbosity as JSON. And personally, after writing plenty of both by hand, XML is easier to get right. JSON, with it's poor quoting rules (mandatory quotes on names??) and lack of comments is very annoying to do by hand and seems visually more noisy.
Re:How to Avoid Being Called a Bozo When Producing XML (2005) by erlehmann_ on Sunday July 31, 2016 @08:04PM (#12199526)
An advantage of names in end tags is human readability. Consider this XML fragment:

  <a>12<b>34<c>56<d>78<e>90</e></d></c></b></a>
Appending something to the end of the d element is easy, since one can just search for its end tag. In JSON and other formats that only have one single character at the end, one has to count brackets or parentheses for this purpose:

  (12(34(56(78(90)))))
Re:How to Avoid Being Called a Bozo When Producing XML (2005) by mikeash on Sunday July 31, 2016 @11:51PM (#12200092)
If they're all <a> then you're back to square one.

JSON solves this with indentation, pretty printing, and using paired symbols that most conpetent editors can automatically balance. This solves the homogeneous case too.

Incidentally, XML can benefit from the first two, and many editors balance tags, so you can get the same thing there.

Re:How to Avoid Being Called a Bozo When Producing XML (2005) by erlehmann_ on Monday August 01, 2016 @03:19AM (#12200696)
It is rare in real-world XML that elements have children with the same type. Do you have a (non-divitis) example where the tags are all the same?
Re:How to Avoid Being Called a Bozo When Producing XML (2005) by lmm on Monday August 01, 2016 @05:43AM (#12201149)
It happens with any tree structure. E.g. I used to work on a system that managed reinsurance contracts and represented them as trees of contracts.
Re:How to Avoid Being Called a Bozo When Producing XML (2005) by erlehmann_ on Monday August 01, 2016 @06:38AM (#12201345)
Did the elements often have immediate child elements that had immediate child elements (and so on) of the same type? Like:

  <contract><contract><contract><contract> […]
Re:How to Avoid Being Called a Bozo When Producing XML (2005) by lmm on Monday August 01, 2016 @07:13AM (#12201507)
No, there were a couple of layers in that case. But that doesn't actually help you add a child at the correct level, because the end of a contract would look something like:

                ...
                </contract>
              </subcontracts>
            </content>          
          </contract>
        </subcontracts>
      </content>
    </contract>
Re:How to Avoid Being Called a Bozo When Producing XML (2005) by JoshTriplett on Sunday July 31, 2016 @03:29PM (#12198449)
> I think that XML's bad reputation comes from the fact that it is <adverbial-particle modifies="#123">so</adverbial-particle> <adverb id="123">incredibly</adverb> <adjective>verbose</adjective>.

> Also, the whole child/attribute dichotomy is a huge, huge mistake.

Those two factors run counter to each other. Attributes decrease verbosity, compared to child elements.

I agree, though. A few changes would make XML closer to ideal: eliminate attributes and eliminate the name in closing tags (<tagname>value</>), which makes child elements much less verbose, and reduces the need for attributes.

Re:How to Avoid Being Called a Bozo When Producing XML (2005) by wtbob on Sunday July 31, 2016 @04:04PM (#12198581)
> A few changes would make XML closer to ideal: eliminate attributes and eliminate the name in closing tags (<tagname>value</>), which makes child elements much less verbose, and reduces the need for attributes.

Then just change '<tagname>' to '(tagname,' and '</>' to ')' and you'll have S-expressions.

Consider this:

    (feed
     (version 1)
     (title "Example Feed")
     (link http://example.org/)
     (updated "2003-12-13T18:30:02Z")
     (author (name "John Doe"))
     (id urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6)
    
     (entry
      (title "Atom-Powered Robots Run Amok")
      (link http://example.org/2003/12/13/atom03)
      (id urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a)
      (updated "2003-12-13T18:30:02Z")
      (summary "Some text.")))
That is a canonical S-expression (for a Scheme or Common Lisp reader, just quote the URIs too) version of:

    <?xml version="1.0" encoding="utf-8"?>
    <feed xmlns="http://www.w3.org/2005/Atom">
    
    <title>Example Feed</title>
    <link href="http://example.org/"/>
    <updated>2003-12-13T18:30:02Z</updated>
    <author>
    <name>John Doe</name>
    </author>
    <id>urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6</id>
    
    <entry>
    <title>Atom-Powered Robots Run Amok</title>
    <link href="http://example.org/2003/12/13/atom03"/>
    <id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id>
    <updated>2003-12-13T18:30:02Z</updated>
    <summary>Some text.</summary>
    </entry>
    
    </feed>
I particularly like how URIs are sometimes encoded as attributes and sometimes as child text elements.

And compare to your proposed version:

    <feed>
    
    <title>Example Feed</>
    <link>http://example.org/</>
    <updated>2003-12-13T18:30:02Z</>
    <author>
    <name>John Doe</>
    </>
    <id>urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6</>
    
    <entry>
    <title>Atom-Powered Robots Run Amok</>
    <link>http://example.org/2003/12/13/atom03</>
    <id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</>
    <updated>2003-12-13T18:30:02Z</>
    <summary>Some text.</>
    </>
    
    </>
I think it's pretty clear which is the most readable and elegant.
Re:How to Avoid Being Called a Bozo When Producing XML (2005) by JoshTriplett on Sunday July 31, 2016 @04:37PM (#12198712)
If you're going to compare the two fairly, include appropriate indentation for both, not just the S-expression version. Also put the author and name tags on the same line, as you did with the S-expressions:

    <feed>
      <title>Example Feed</>
      <link>http://example.org/</>
      <updated>2003-12-13T18:30:02Z</>
      <author><name>John Doe</></>
      <id>urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6</>
    
      <entry>
        <title>Atom-Powered Robots Run Amok</>
        <link>http://example.org/2003/12/13/atom03</>
        <id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</>
        <updated>2003-12-13T18:30:02Z</>
        <summary>Some text.</>
      </>
    </>
That said, I like S-expressions too, and I wish more parsers and tools existed for them, such as schemas, query tools, and simple transformation tools.
Re:How to Avoid Being Called a Bozo When Producing XML (2005) by wtbob on Sunday July 31, 2016 @06:18PM (#12199190)
> If you're going to compare the two fairly, include appropriate indentation for both, not just the S-expression version.

When I pasted it in from https://validator.w3.org/feed/docs/atom.html#sampleFeed I guess I lost the indents. No idea why: they are clearly there in the original.

Re:How to Avoid Being Called a Bozo When Producing XML (2005) by j4_james on Monday August 01, 2016 @07:48PM (#12206960)
> I particularly like how URIs are sometimes encoded as attributes and sometimes as child text elements.

I think the distinction here is that the one is an identifier which is not intended to be dereferencable, and the other is a link to a resource which has to be retrievable. In the good old days the id would most likely have been a URN and the link a URL, but that distinction was being discouraged in favour of the more general URI term at the time the Atom spec was developed. [1]

So while they're syntactically both URIs (well technically IRIs), they're functionally quite different. It may be debatable whether that's a good enough reason for the one to be an element value and the other an attribute value, but I don't think that decision was obviously wrong.

[1] https://tools.ietf.org/html/rfc3986#section-1.1.3

Re:How to Avoid Being Called a Bozo When Producing XML (2005) by erlehmann_ on Sunday July 31, 2016 @08:00PM (#12199515)
The second and third examples do not have namespaces.

How would you include an HTML summary, for example?

Re:How to Avoid Being Called a Bozo When Producing XML (2005) by wtbob on Sunday July 31, 2016 @09:05PM (#12199675)
> The second and third examples do not have namespaces.

> How would you include an HTML summary, for example?

As a text attribute, honestly — which would be necessary in XML as well (you could embed XHTML in XML, but not HTML). And in the general case, embedding one variant of XML inside another, rather than embedding a character-encoded variant of XML inside another, doesn't seem all that useful. How often do transforms need to reach all the way in like that?

I guess it's cool if it's possible, which is why I like S-expressions all the way down. But I don't think it's all that useful, as opposed to neat.

Re:How to Avoid Being Called a Bozo When Producing XML (2005) by erlehmann_ on Monday August 01, 2016 @03:27AM (#12200722)
> How often do transforms need to reach all the way in like that?

In my experience, almost every time XSLT is used on real-world documents, those are documents with multiple namespaces. XSLT stylesheets themselves are also documents that have multiple namespaces. Example: Atom feeds often contain XHTML content. It is a common problem with RSS that it does not specify if the content of an element is HTML or plain text.

I have found that arguments that doubt a feature is necassary from people who can not imagine use cases are almost invariably wrong, while arguments that doubt a feature is necessary from people who list use cases and why they think those are better solved otherwise or even left unsolved are often right. Your post seems like an example of the former; would you say that complex real-world content with namespaces could sway you in favor of them?

Re:How to Avoid Being Called a Bozo When Producing XML (2005) by lmm on Monday August 01, 2016 @05:48AM (#12201168)
I would be convinced if I saw real-world examples where having namespaces gave an advantage over not having namespaces. I can see the value in specifying whether the content of a given node is XHTML or text. I can at least theoretically see value in allowing nesting XHTML without a layer of escaping. I can't see any non-theoretical way in which namespaces are necessary to accomplish these things.
Re:How to Avoid Being Called a Bozo When Producing XML (2005) by erlehmann_ on Monday August 01, 2016 @05:56AM (#12201204)
Example: The XSLT stylesheet for this Atom feed generates a web page for each entry: http://news.dieweltistgarnichtso.net/notes/index.xml In this setup, the Atom XML for each entry is generated from XHTML with XSLT, which makes it possible to automatically include an Atom enclosure element for every XHTML media element. To publish a podcast episode, it is enough to add a post with an <audio> or <video> element, as an XSLT stylesheet can “reach into” the XHTML content.

Namespaces are also widely used in SVG, which uses the XLink specification for hyperlinks and can embed XHTML and MathML content. Since SVG can be embedded in (X)HTML, this means you can have an ATOM feed containing XHTML containing MathML and SVG that contains XHTML and all have it displayed correctly.

Re:How to Avoid Being Called a Bozo When Producing XML (2005) by lmm on Monday August 01, 2016 @06:04AM (#12201231)
> Example: The XSLT stylesheet for this Atom feed generates a web page for each entry: http://news.dieweltistgarnichtso.net/notes/index.xml

> In this setup, the Atom XML for each entry is generated from XHTML with XSLT, which makes it possible to automatically include an Atom enclosure element for every XHTML media element. To publish a podcast episode, it is enough to add a post with an <audio> or <video> element.

Sure. Why do you need namespaces to do that? Why couldn't you do it in XML-without-namespaces (or even JSON and some theoretical JSON-transformation-lanugage?)

> Namespaces are also widely used in SVG, which uses the XLink specification for hyperlinks and can embed XHTML and MathML content.

Again, why are namespaces necessary though? Why not just have a tag whose content is specified to be XHTML/MathML ? Wouldn't you want that anyway for the sake of human readability?

Re:How to Avoid Being Called a Bozo When Producing XML (2005) by erlehmann_ on Monday August 01, 2016 @06:22AM (#12201277)
XML without namespaces does not exist. If it existed, how would you differentiate between title and link elements in Atom and title and link elements in XHTML? They have the same element names, but do not have the same meaning and therefore must be processed differently. Namespaces ensure that any XML processor can know the language of each part of the input.

Namespaces actually are the general mechanism with which you can specify that content is in another language: If you look at the feed source code, you can see that XHTML content is started with <div xmlns="http://www.w3.org/1999/xhtml"> and ends where that div element is closed.

Having an element with the semantics that “this content is in another language” is done out of necessity in HTML, as it has no namespacing: <style> elements contain CSS, <script> elements contain JavaScript, <svg> elements contain SVG … having an element in each language to embed each other language would become complicated very fast.

Re:How to Avoid Being Called a Bozo When Producing XML (2005) by lmm on Monday August 01, 2016 @07:09AM (#12201492)
> XML without namespaces does not exist. If it existed, how would you differentiate between title and link elements in Atom and title and link elements in XHTML?

By where it is in the structure. The document is a tree where each element has well-defined context; there should never be confusion about whether a particular <title> is part of the feed or part of the content in the feed, because if it's in content it will be inside the content tag.

(Don't you need to do that anyway? I mean what if the XHTML had another Atom feed embedded in it? Or the content of one of the entries in the feed was another Atom feed? That's legitimate, but you wouldn't want to show titles from the "inner" feed as titles in the feed).

> Having an element with the semantics that “this content is in another language” is done out of necessity in HTML, as it has no namespacing: <style> elements contain CSS, <script> elements contain JavaScript, <svg> elements contain SVG … having an element in each language to embed each other language would become complicated very fast.

Only if you need the ability to embed an arbitrary other language. And if you do need that you can't possibly be validating or transforming based on what's embedded, so what value is the namespacing of it giving you?

Re:How to Avoid Being Called a Bozo When Producing XML (2005) by Mikhail_Edoshin on Monday August 01, 2016 @08:05AM (#12201730)
You may have incomplete documents (e.g. documents with conditional sections, very much like XSLT):

    <code:if test="...">
      <!-- whatever -->
    <code:else>
      <!-- whatever -->
    </code:if>
Here you'll first process your code part an copy the contents as they are and then process the contents; but in the source document the two languages are interspersed.

Or you may want to extend your text format with, say, literate programming and add code fragments and files. In my homegrown system it's like that:

    <literate:fragment id="..." language="...">
      <text:caption>...</text:caption>
      <literate:code>...</literate:code>
    </literate:fragment>
My text system already has a notion of captions so there's no need to add my own "literate:caption" here. Yet the other two "literate" elements are new an unique. Also, using a namespace here ensures that I'm sure not to have a clash if the base system adds their own "fragment" or "code" blocks.
Re:How to Avoid Being Called a Bozo When Producing XML (2005) by lmm on Monday August 01, 2016 @08:35AM (#12201850)
OK, I guess that takes things a level up. I don't like that kind of interspersed style and I don't think incomplete documents should be the same kind of thing as complete ones (e.g. one can't meaningfully validate your first example, because what if the "whatever" is an element that has to be present exactly once). But I can see that if you want to write things this way then namespaces help.
Re:How to Avoid Being Called a Bozo When Producing XML (2005) by erlehmann_ on Tuesday August 02, 2016 @06:36AM (#12208929)
“I don't like” seems to be an æsthetic argument, not a technical one.
Re:How to Avoid Being Called a Bozo When Producing XML (2005) by erlehmann_ on Monday August 01, 2016 @07:33AM (#12201589)
> The document is a tree where each element has well-defined context; there should never be confusion about whether a particular <title> is part of the feed or part of the content in the feed, because if it's in content it will be inside the content tag.

In this specific case, maybe – but generally, it is not true that you can infer the namespace of an element from context. Also, elements can have multiple attributes with different namespaces (and often do).

> I mean what if the XHTML had another Atom feed embedded in it? Or the content of one of the entries in the feed was another Atom feed? That's legitimate, but you wouldn't want to show titles from the "inner" feed as titles in the feed

That actually appears to be a bug in my stylesheet. Thank you for bringing it to my attention!

Programs often use namespaces to provide metadata. Here is an SVG I created with Inkscape that uses six different namespaces for metadata: http://daten.dieweltistgarnichtso.net/pics/icons/minetest/mi... Thanks to namespacing, web browsers can display the picture while ignoring Inkscape-specific data.

> Only if you need the ability to embed an arbitrary other language. And if you do need that you can't possibly be validating or transforming based on what's embedded, so what value is the namespacing of it giving you?

It is very useful to embed any arbitrary language, as XML processors can preserve the content they do not understand without processing it. My XSLT stylesheet would have no issue with SVG embedded in XHTML, just as your web browser most likely ignores everything about the SVG linked above it can not understand.

Re:How to Avoid Being Called a Bozo When Producing XML (2005) by lmm on Monday August 01, 2016 @08:48AM (#12201918)
> It is very useful to embed any arbitrary language, as XML processors can preserve the content they do not understand without processing it. My XSLT stylesheet would have no issue with SVG embedded in XHTML, just as your web browser most likely ignores everything about the SVG linked above it can not understand.

Sure, but you can ignore extra attributes in JSON or hypothetical XML-without-namespacing too. I feel like there's an excluded middle here: either the content of a given tag has to be, say, SVG, in which case the validation schema for the outer document could just say (in a structured way) "the content of this tag must be a valid SVG document according to the SVG schema", or the content is some opaque arbitrary XML document, in which case there's no meaningful validation to be done.

Even when working with something like XHTML-with-embedded-SVG, I found myself wishing there was a way to strip the namespaces, run my xpath queries / xslt transformations on the stripped version, and then put the namespaces back; I think I'd've got my actual business tasks done a lot quicker that way.

Re:How to Avoid Being Called a Bozo When Producing XML (2005) by erlehmann_ on Tuesday August 02, 2016 @06:03AM (#12208824)
Ignoring other attributes in data formats without namespaces is not as easy. What if one language is embedded in another and each one has a title element?

I do not know why you “feel” that way about the middle you want to exclude. It has been proven to be very useful in practice for me. Also without it, XML would not have the “extensible” property.

The way you describe working with “XHTML-with-embedded-SVG” reads to me like there is something about namespaces or your toolchain that you have difficulties with. I found that with XML-based systems, especially XSLT, it is easy to make a task needlessly complicated if one does not understand the details.

Re:How to Avoid Being Called a Bozo When Producing XML (2005) by Mikhail_Edoshin on Monday August 01, 2016 @07:39AM (#12201613)
The creators of XML were aware that it was verbose; they mention in their design goals that this was the least priority.

Child and attribute "dichotomy" is not a mistake. What you mean is that these two samples appear to be equivalent:

    <foo value="123" />
    <foo>123</foo>
But they are not equivalent. The first line (with an attribute) is there solely for the computer. When the document is rendered, the human user is not supposed to see anything there unless the computer adds it.

The second line (with text content) is there for both the computer and the human user. The text "123" is for the human user; the fact that this text is something called "foo" is for the computer. When the document is rendered, the human user will see "123" here. Maybe computer will enhance something or maybe it will just use it as index or reference, whatever.

Most people who don't like XML seem to only encounter it in config files. In config files there's normally no content that needs to be there for the end users, so all data can happily go into attributes. The text content starts to matter when we deal with natural language texts.

Re:How to Avoid Being Called a Bozo When Producing XML (2005) by wtbob on Monday August 01, 2016 @09:00AM (#12201988)
> The creators of XML were aware that it was verbose; they mention in their design goals that this was the least priority.

Which seems pretty wasteful.

> Child and attribute "dichotomy" is not a mistake.

It's not for a markup format — as I mentioned, it can make sense there — but, as you mentioned, it doesn't make sense in a config or data file format.

Re:How to Avoid Being Called a Bozo When Producing XML (2005) by legulere on Sunday July 31, 2016 @03:16PM (#12198389)
The problem is that XML maps badly to data structures in common programming languages. JSON maps perfectly to structs and datastructures as lists/arrays/maps.

S-expressions are good if you work with Lisp like languages, but I don't think they're very readable if you're not into Lisp. I also can't see how they map easily into datastructures of imperative programming languages or even statically typed functional programming languages like haskell.

Re:How to Avoid Being Called a Bozo When Producing XML (2005) by wtbob on Sunday July 31, 2016 @04:14PM (#12198624)
> S-expressions are good if you work with Lisp like languages, but I don't think they're very readable if you're not into Lisp.

Take a look at https://news.ycombinator.com/item?id=12198581; I think it demonstrates how readable one dialect of S-expressions can be.

> I also can't see how they map easily into datastructures of imperative programming languages

JSON consists of numbers, strings, booleans, objects and arrays; canonical S-expressions consist of bytes and lists. I contend that one can easily encode strings, numbers and booleans alike as bytes, and both objects and arrays as lists. Consider:

    {
        "id": 1234,
        "isEnabled": true,
        "props": ["abc", 123, false],
    }
This could be encoded in canonical S-expressions as:

    (object
     (id "1234")
     (is-enabled "true")
     (props (abc "123" "false")))
Granted, one still must convert the strings "1234," "true," "123," and "false" into the expected types, but with JSON one still must check the expected types anyway; it's not that big a difference.

And I honestly think that the S-expression version is far more attractive.

Re:How to Avoid Being Called a Bozo When Producing XML (2005) by zyxley on Sunday July 31, 2016 @06:50PM (#12199292)
You could do make it more like S-expressions in JS if you really wanted.

    {object: [
      {id: "1234"},
      {isEnabled: "true"},
      {props: ["abc", "123", "false"]}]}
Not quite the same, but nothing keeps you from parsing an array of key/value pairs instead of a hash.
Re:How to Avoid Being Called a Bozo When Producing XML (2005) by wtbob on Sunday July 31, 2016 @09:07PM (#12199684)
You may not leave JSON object properties unquoted, so it'd have to read:

    {"object": [
      {"id": "1234"},
      {"isEnabled": "true"},
      {"props": ["abc", "123", "false"]}]}
So you have extraneous quotes, extraneous semicolons, extraneous commas, plus the parsing code is complicated by having to handle all of that rather than atoms & lists (that's not a strong reason, since parsing code is written once and used millions of times).

I really, really don't get the visceral opposition to S-expressions. From my perspective they're both better & simpler.

Re:How to Avoid Being Called a Bozo When Producing XML (2005) by PeterisP on Sunday July 31, 2016 @06:47PM (#12199283)
There is a very big difference - "with JSON one still must check the expected types anyway" is not really true, I can deserialize an arbitrary json and I will know the difference between 123 and "123" even if I don't know what's expected or, alternatively, mixed-type values are expected.
Re:How to Avoid Being Called a Bozo When Producing XML (2005) by wtbob on Sunday July 31, 2016 @09:10PM (#12199687)
> There is a very big difference - "with JSON one still must check the expected types anyway" is not really true, I can deserialize an arbitrary json and I will know the difference between 123 and "123" even if I don't know what's expected or, alternatively, mixed-type values are expected.

You will still need, in your code, to handle both 123 & "123" (or handle one, and error on the other). That's really no different from, in your code, parsing "123" as an integer, or throwing an error.

In JSON one must check that every value is the type one expects, or throw an error. With canonical S-expressions, one must parse that every value is the type one expects, or throw an error. There's really no difference.

If one is willing to use a Scheme or Common Lisp reader, of course, then numbers &c. are natively supported, at the expense of more quoting of strings (unless one chooses to use symbols …).

Re:How to Avoid Being Called a Bozo When Producing XML (2005) by lmm on Monday August 01, 2016 @05:50AM (#12201176)
> You will still need, in your code, to handle both 123 & "123" (or handle one, and error on the other). That's really no different from, in your code, parsing "123" as an integer, or throwing an error.

It is different because in the latter case you have to write your own code to do it, while in the former your library will handle it for you.

> If one is willing to use a Scheme or Common Lisp reader, of course, then numbers &c. are natively supported, at the expense of more quoting of strings (unless one chooses to use symbols …).

So this format comes in dozens of partially-incompatible variants? Lovely.

Re:How to Avoid Being Called a Bozo When Producing XML (2005) by ZenoArrow on Sunday July 31, 2016 @11:22AM (#12197333)
> "The best human-readable data transfer format is probably canonical S-expressions"

I personally think TOML is a bit more readable...

https://github.com/toml-lang/toml

Re:How to Avoid Being Called a Bozo When Producing XML (2005) by legulere on Sunday July 31, 2016 @03:03PM (#12198343)
For configuration files, not for data serialisation.
Re:How to Avoid Being Called a Bozo When Producing XML (2005) by ZenoArrow on Monday August 01, 2016 @02:52AM (#12200613)
Let's put it like this... what can you express in JSON that you couldn't express in TOML?
Re:How to Avoid Being Called a Bozo When Producing XML (2005) by lmm on Monday August 01, 2016 @05:52AM (#12201183)
I can cleanly parse JSON, serialize it, and be confident I haven't lost anything. That can't be done for a language that allows comments without complicating the AST.
Re:How to Avoid Being Called a Bozo When Producing XML (2005) by crdoconnor on Monday August 01, 2016 @07:50AM (#12201659)
YAML is more readable than TOML though.
Re:How to Avoid Being Called a Bozo When Producing XML (2005) by einhverfr on Sunday July 31, 2016 @10:54AM (#12197216)
XML is very often the least bad format (compared with ASN.1, JSON, X12 EDI, CSV, and other interchange formats), particularly when dealing with statically typed languages. XML is a horrid chimera of SGML but at least it is both human readable, subject to machine validation, and gets the job done.
Re:How to Avoid Being Called a Bozo When Producing XML (2005) by cptskippy on Sunday July 31, 2016 @09:20PM (#12199712)
Oh EDI... you made me shudder.
Re:How to Avoid Being Called a Bozo When Producing XML (2005) by einhverfr on Sunday July 31, 2016 @11:09PM (#12200003)
No experience with ASN.1?
Re:How to Avoid Being Called a Bozo When Producing XML (2005) by cptskippy on Monday August 01, 2016 @09:39AM (#12202259)
Nope. I ran into EDI when I was doing an integration for a JIT Hub that had to integrate with Hitachi and Seagate inventory systems. It was pretty awful to work with but the protocol was rock solid.
Re:How to Avoid Being Called a Bozo When Producing XML (2005) by qwertyuiop924 on Sunday July 31, 2016 @10:32AM (#12197112)
Well, XML is complicated, so it's hard to build support for, and it's verbose, so it's heavy on the wire. Frankly, I think JSON is a better format in most contexts.
Re:How to Avoid Being Called a Bozo When Producing XML (2005) by barrkel on Sunday July 31, 2016 @10:47AM (#12197168)
The biggest problem with XML is that it's a node labeled tree that makes the schema choice between leaf node and attribute for scalar data almost arbitrary, whereas JSON is an edge labeled tree without the same choice. Most programming languages use edge labeled graphs for in memory data structures, so the semantic distance is lower with JSON.
Re:How to Avoid Being Called a Bozo When Producing XML (2005) by beagle3 on Sunday July 31, 2016 @10:55AM (#12197218)
Indeed. Furthermore, JSON readily differentiates between a single element {a: 'hello'} and a vector with one element {b: ['hello']}, as do most programming languages. XML does not, which leads to weird constructs like <Names><Name>a</Name></Names> to indicate that more than one name is possible. (Except .. if you actually use a schema with your XML parser, that indicates more than one is possible. But almost no one does). JSON also differentiates numbers from strings, etc.

As a result, in my experience, JSON tends to be more robust in real world use - even when a schema is available.

Re:How to Avoid Being Called a Bozo When Producing XML (2005) by nialo on Sunday July 31, 2016 @04:50PM (#12198777)
Can you explain what you mean by JSON being an edge labeled tree in more detail? I don't understand and would really like to.
Re:How to Avoid Being Called a Bozo When Producing XML (2005) by zachrose on Sunday July 31, 2016 @06:28PM (#12199235)
Taking a stab at this...

Let's say we have a dog who has four paws. In XML:

    <dog>
      <paw health="ok">
      <paw health="ok">
      <paw health="ok">
      <paw health="ok">
    </dog>
In JSON:

    { "paws": [
        { "health": "ok" },
        { "health": "ok" },
        { "health": "ok" },
        { "health": "ok" },
    ] }
I think what the GP is getting at is that JSON is always describing the relationships between a thing and another thing, rarely the things themselves. In the JSON version, for example, it can be assumed that an object in the "paws" array is a paw.

This example is sort of a straw man. The JSON version could be wrapped with { "dog": {...} } and the individual XML paws could be wrapped in a <paws> element. But in any case, JSON doesn't need you to give an explicitly label the type of each paw, just what they belong to and what's known about them.

Re:How to Avoid Being Called a Bozo When Producing XML (2005) by qwertyuiop924 on Sunday July 31, 2016 @08:05PM (#12199532)
I'll step up to the plate to give a more technical answer.

JSON is an edge labelled tree, XML is node labelled tree. Let's see what that means, but first, let's talk about what nodes, edges, trees, and labels. You may already know, but I don't want to make no assumptions.

First, a tree: A tree is a datastructure with nodes, which reference other nodes, and each node is only referred to by one other node. Now, XML is obviously a tree, with each tag being a node:

       <dog>
       /| |\ 
      / | | \
     /  | |  \
  <paw> | | <paw>
        / \
       /   \
      /     \
    <paw>  <paw>
However JSON is also a tree: however, instead of tags, we have arrays and objects:

Well, actually, I'm not going to draw that. I'm typing on a phone, and it was hard enough making that last one. So, you know, just imagine it. And if you imagine hard enough, you just might notice that this graph is edge labelled, rather than node labelled.

A node, as you may recall, is just a thing on the tree, like a tag, or an object or an array. Queue the music!

  TO THE TUNE OF "NOUNS" FROM SCHOOLHOUSE ROCK:
  Oh any list through which you can go (like a array, a linked list, or an arraylist),
  And any structure that you can show (like a hashmap, or a struct),
  If they have pointers you can follow (from an object in a tree),
  You know they're nodes, you know they're nodes
Aaaanyway, an edge is the link between two nodes, and labels are just names.

JSON labels edges: "I want the first value in the array you got at key "foo" from the root object."

XML labels nodes: "I want the paragraph tag with the id of 'foo' inside the body tag inside the html tag."

You see, with the JSON, the nodes themselves didn't have labels, just the links between them: With XML, it was the opposite: There was no name for the links, instead there were names for the objects.

GGP reminds us that most programming languages do it the same way JSON does (when was the last time referred to the Foo object in the Bar object in the head Baz object when coding?), and so JSON maps better to the kind of datastructures we use most of the time.

Re:How to Avoid Being Called a Bozo When Producing XML (2005) by MichaelMoser123 on Monday August 01, 2016 @02:27AM (#12200536)
I don't quite see why you can't do the same with xml; maybe it needs some more typing, but it is expressing the same thing.

  <paws>
    <health status="ok"/>
    <health status="ok"/>
    <health status="ok"/>
    <health status="ok"/>
  </paws>
i thought that the main advantage of json was that it can be used as is (code as data) in javascript, but the problem here of course is that without a parser/validator one can inject tons of malicious code. If you are not on javascript then you can't do without a parser / in memory tree structure - and that's the same DOM model once again.

Json needs a bit less typing, now is that really such a significant difference? i think that adoption in matters of markup is more like a fashion - once people got the hang of it then it seems natural and goes without explanation.

i would say that there is one major difference - binary or text; as long as its text then it doesn't quite matter how you structure your markup; if you need your data to be of small size then you will have to compress it; however the parsing of a text tree will usually take more time than the serialization of a binary structure (by several factors);

Therefore you will use text markup where application speed is not very important, or where speed of development is more important than application performance, or you will use it for complicated configuration data (and your users will hate you because a name value format like ini files is easier to handle - well, mostly)

Re:How to Avoid Being Called a Bozo When Producing XML (2005) by lmm on Monday August 01, 2016 @05:54AM (#12201195)
> I don't quite see why you can't do the same with xml; maybe it needs some more typing, but it is expressing the same thing.

It's not idiomatic though - the dog's paws aren't "healths". The point is that in XML each tag is expected to have a label and be an entity in its own right, whereas in JSON you expect each field to be an attribute.

Re:How to Avoid Being Called a Bozo When Producing XML (2005) by barrkel on Monday August 01, 2016 @08:14AM (#12201756)
Graph theory terminology: nodes are connected by edges. When drawn, the edges are the lines, the nodes are the blobs that are connected by lines.

All trees are graphs. Not all graphs are trees; there could be cycles, or children with multiple parents in an arbitrary graph.

In JSON, the nodes are literals: numbers, strings, booleans, arrays, hashes (object constructors). The edges are hash keys (object field names in the constructors).

In XML, the nodes themselves have the names. The edges are implicit in the syntax via containment, and are unlabeled.

In programming languages, generally our values don't have names. Instead, our variables have names, and refer to values; variables can be assigned different values, but the name doesn't change. More physically, if the values are stored on the heap, variables are pointers to values on the heap, and fields of heap objects are further pointers to more values on the heap. Here, variables and fields are edges, and the values are the nodes. Looked at from a graph theory perspective, the in-memory model is an edge labeled graph.

Re:How to Avoid Being Called a Bozo When Producing XML (2005) by qwertyuiop924 on Sunday July 31, 2016 @11:08AM (#12197278)
Indeed. Even translating to Lisp, which has closer datastructures than most languages, the XML is translated to an edge-labeled tree.
Re:How to Avoid Being Called a Bozo When Producing XML (2005) by marktangotango on Sunday July 31, 2016 @10:57AM (#12197223)
Great explanation, I'd never heard it put that way before, thanks!
Re:How to Avoid Being Called a Bozo When Producing XML (2005) by chrisseaton on Sunday July 31, 2016 @10:46AM (#12197164)
What do you think JAVA stands for? It's not an abbreviation. It's the name of an island and it's just 'Java'.
Re:How to Avoid Being Called a Bozo When Producing XML (2005) by Cpoll on Sunday July 31, 2016 @11:05AM (#12197264)
It's more accurate to say that it's named for the coffee beans that come from said island.
Re:How to Avoid Being Called a Bozo When Producing XML (2005) by trav4225 on Sunday July 31, 2016 @03:00PM (#12198324)
It's even more accurate to say that it's named for the coffee made from the coffee beans that come from said island. ;-)
Re:How to Avoid Being Called a Bozo When Producing XML (2005) by djur on Sunday July 31, 2016 @01:09PM (#12197758)
Ruby has had an included XML library since before Rails was released. soap4r is older than Rails too. I wrote my share of clients for SOAP services back then. soap4r wasn't fun to use but it mostly worked. If the service was really simple (a single call and response, for instance) it was sometimes more expedient to put together the request yourself.

When Savon came out 6-7 years ago it was a huge relief. Luckily, by that point, I was seeing a lot less SOAP. But even with Savon, the experience was only lifted to "not awful", never to "wow, I'm glad they used SOAP, this is so easy."

Re:How to Avoid Being Called a Bozo When Producing XML (2005) by saurik on Sunday July 31, 2016 @01:44PM (#12197923)
My experience with early Ruby XML parsers is that they were all "how hard can this be?" hacks someone did over a weekend by people who didn't really use XML or understand the ecosystem of specifiations and thereby barely worked and often didn't support fundamental things like namespaces correctly. It took away everything which made XML powerful and left you with something that was often even finicky.
Re:How to Avoid Being Called a Bozo When Producing XML (2005) by flomo on Sunday July 31, 2016 @10:36PM (#12199935)
Yeah, I worked on a Rails 1.x app which integrated with an xml feed. IIRC, the options were a library that used regexes internally and had horrible performance (but might have been fine for rss feeds), and another library which wrapped a C library and used callbacks[1]. Definitely was a huge pain point and probably was a mistake for me to use the latest hep environment for that app, but for the rest of Rails it might have been worth it.

[1] I think it might have been http://www.yoshidam.net/Ruby.html#xmlparser

Re:How to Avoid Being Called a Bozo When Producing XML (2005) by SomeCallMeTim on Sunday July 31, 2016 @04:55PM (#12198807)
>well regarded in the enterprise

I think this alone should be enough to cast doubt on it, based on my (albeit limited) interactions with "enterprise" software.

>I think it's bad reputation comes from anyone not using an enterprise language because the support just isn't there.

What, like JavaScript? I've had to read and write XML packets from a Node app to work with (surprise!) an enterprise app. I had probably 20 choices of libraries with varying levels of features, and the one I chose worked fine.

I was lucky, compared to some of the others on this page: The "RPC"-style XML commands and responses I had to parse and generate were all well standardized, so I just wrote a wrapper that extracted the completely opaque tree of XML into a flatter JavaScript object/hash that was really easy to deal with, and similarly made a wrapper that would trivially generate the monstrous XML required to send commands and responses back to the server. My JSON-equivalent objects were easier to manipulate (and would also have been easier to deal with in Java or, in this case, C#), equally rich in the information they carried, but could have been serialized with 1/3 the number of bytes per message. Totally a win-win-win.

What I don't understand is why anyone thought using XML that way was a good idea, and why it still is popular in the enterprise. Bad habits are hard to break, I guess.

Re:How to Avoid Being Called a Bozo When Producing XML (2005) by clockwerx on Sunday July 31, 2016 @08:38PM (#12199614)
> What I don't understand is why anyone thought using XML that way was a good idea, and why it still is popular in the enterprise. Bad habits are hard to break, I guess.

Namespaces, which then gives you easy answers for Internationalisation (xml:lang), a subject-predicate-object data structure (RDF), which can lead on to logical meaning/modelling of data (RDFS/OWL), which then lets you look at harder questions like trust/provenance.

There's also schema validation (XSD), transformation (XSLT), which then provides you tools like XPath.

Most of that is on the front page for the technology: https://www.w3.org/standards/xml/

The real problem is not syntax, its communication between groups with differing experiences and interests - how do I know your messages mean the same thing as what my system expects?

If you prove to be malicious, do I have to write a strict validator before I trust your input?

If you want to ensure your messages are well formed before they are sent, do you also have to write a validator?

How do I know our validators are checking the same things?

If you want to send a large document oriented data structure, but I only care about a specific section relating to my interests; do I have to understand where to look and what all of the surrounding material is; or can I query for the relevant bits?

On the more complicated RDF side of things - if you want to share identifiers with me, how do we both avoid calling everything record id=1?

If we are both talking about the same thing but know different parts of the story, how can I recognize your information as describing the same thing I know about?

If we both know about the same Thing, and know certain logical facts about that Thing, can we check those facts actually make sense against shared rules?

If we both know about the same Thing, and can see a logical inconsistency in data, can we reason about which data to Trust and why?

Unfortunately, communicating properly is hard even with all of the tools to help.

We tend to opt towards subjecting systems to an ongoing fuzzing test because we don't value many of the above things - we tend to work in organisations with a short attention span focused on the now and a narrow set of interests. It just kind of works for the 80% of the time, so we move on.

Contrast that with something like a library or museum, and you see why ideas like Dublin Core really catch on there.

Re:How to Avoid Being Called a Bozo When Producing XML (2005) by SomeCallMeTim on Monday August 01, 2016 @02:48PM (#12204876)
Sounds great in theory. In practice it doesn't seem nearly as carefully implemented, and/or XML is used where it's actually not needed.

XML is designed to be a markup language. The fact that it has all of these other things bolted on doesn't actually make it a good generic data interchange format.

For things like RDF, maybe it's the best option we have, but that's not because XML is great, it's because XML was used in the only standardized option.

Looking at an example of xml:lang:

    <?xml version="1.0" encoding="utf-8" ?>
    <doc xml:lang="en">
     <list title="Titre en français" xml:lang="fr">
      <p>Texte en français.</p>
      <p xml:lang="fr-ca">Texte en québécquois.</p>
      <p xml:lang="en">Second text in English.</p>
     </list>
     <p>Text in English.</p>
    </doc>
...this is a nightmare. If I want to translate a document, the last thing I want to do is embed each translation inline like that. Almost certainly the best response is to "fork" the document at the highest level and include separate language versions of the document; otherwise, if you have 20 translations of the document, you need 20x the text in the document than any one reader will need.

Yes, XML gives you that particular hammer. But using XML results in a lot of sore thumbs.

Schema validation is nice to be sure. I'm using JSON Schema Validation myself [1] to verify incoming JSON, and I'm automatically generating those schemas from the TypeScript data structure specifications [2]. This is particularly good for a JavaScript language target, of course, but I find XML and XPath to be ugly or painfully slow in every language I've used it from, while JSON just has a better impedance match to data storage and interchange.

[1] http://json-schema.org/

[2] https://github.com/YousefED/typescript-json-schema

Re:How to Avoid Being Called a Bozo When Producing XML (2005) by cptskippy on Sunday July 31, 2016 @09:35PM (#12199751)
> What, like JavaScript?

No, JavaScript is not what I'd consider an enterprise language. I'm talking about C++, C#, VB.NET, Java, and LotusScript. Enterprise languages and enterprise applications (e.g. Siebel) have no problem talking to each other via SOAP/XML and they all produce WSDLs that are easily consumed by one another.

When using something like C# or Java you can easily import a WSDL from another application and the toolchain will automatically generate all of objects defined and properly serialize/deserialize XML into those objects. There's no need to write parsers or use sockets/webclients to talk SOAP.

Newer backend languages and frameworks (e.g. RoR, NodeJS, etc) don't have these mature and robust toolchains for XML/SOAP.

Re:How to Avoid Being Called a Bozo When Producing XML (2005) by int_handler on Sunday July 31, 2016 @10:23PM (#12199898)
My impression is that the reason why XML is so well-regarded in the enterprise is because these companies are not aware of better alternatives, such as Protocol Buffers [1]. The reason why XML has a bad reputation outside of the enterprise is because it is so incredibly verbose (both the language itself and the code used for working with it), and that all-in-all, it is a sub-optimal solution to a solved problem.

To illustrate: Protocol Buffers' wire format is much more compact. It removes the complexity of having to deal with XML parsers by providing classes generated from the message definition/schema. You can use it with GRPC to implement your service APIs. It is supported for many different languages, including Java and C#. It now even has a JSON mapping [2]. Overall, Protocol Buffers can do everything XML can do as both an exchange format and as a configuration language but better.

[1] https://developers.google.com/protocol-buffers/

[2] https://developers.google.com/protocol-buffers/docs/proto3#j...

Re:How to Avoid Being Called a Bozo When Producing XML (2005) by HelloNurse on Monday August 01, 2016 @06:19AM (#12201271)
Protocol Buffers are just one of many proprietary serialization libraries. Regardless of technical excellence, Protocol Buffers and competing libraries are automatically much less suitable for actual enterprise use than open standard serialization protocols with multiple interoperable implementations, such as ASN.1. And of course, XML is usually preferable to ASN.1 or the like because it is equally standardized but it has an ample choice of implementations, advanced tools and human readability and writability.
Re:How to Avoid Being Called a Bozo When Producing XML (2005) by int_handler on Monday August 01, 2016 @04:21PM (#12205582)
Protocol Buffers is not proprietary. It is open source under the BSD license. Here is the source code: github.com/google/protobuf. It is very much an open protocol, and anyone is free to write their own implementation of it. It is just a standards-based protocol.

If your organization values the existence of a standard over technical excellence, then there is no use in convincing you. Otherwise, in terms of ease of use, performance, tooling, and human readability and writability, Protocol Buffers is superior to XML-based protocols (since the API for converting between the binary and text formats is extremely simple to use).

As a fun fact, if you really wanted to use XML as a wire format, you could even write an XmlFormat ser/de for Protocol Buffers, similar to the JsonFormat that is already provided, but then it would defeat one of the main purposes of using Protocol Buffers in the first place because you would replace an extremely performant wire format with an extremely sub-optimal one.

Re:How to Avoid Being Called a Bozo When Producing XML (2005) by chii on Monday August 01, 2016 @06:23AM (#12201283)
Protocol buffer isn't proprietary. It's just not a standards based protocol. But it doesn't stop you from writing code against it, and you can easily interop with a third party who is using protocol buffers.
Re:How to Avoid Being Called a Bozo When Producing XML (2005) by brightball on Sunday July 31, 2016 @11:16PM (#12200016)
Another part of it is that statically typed languages benefit much more from XML with a strictly defined schema like DTD or XSD because it makes it easier to generate the objects that you're going to have to map it into.

With a language like Ruby, PHP, etc that isn't strongly typed it's not nearly as big of a deal. Developers in those languages are used to assuming everything is a string and converting it to something useful without the need to premap every datatype.

That's probably the main reason that XML was so much more popular with the languages you mention compared to the parts of the ecosystem that didn't benefit from it's constructs much (if at all).

Re:How to Avoid Being Called a Bozo When Producing XML (2005) by ambrop7 on Sunday July 31, 2016 @03:21PM (#12198413)
Some time back I needed to generate an XML file in a Java web application. I attempted to figure out how to do it "right". The only "special" requirement was that it is formatted in a readable way.

So I was figuring out the Java XML stuff (don't remember what that was exactly, probably standard). But at some point the timeout in my brain kicked in, and I just wrote a loop generating the XML by brute-force through PrintWriter or something. I even escaped strings right since some library I had available conveniently offered the escape method (Guava maybe?).