this post was submitted on 08 Sep 2024
1232 points (98.3% liked)

Programmer Humor

32469 readers
565 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 9 points 2 months ago (5 children)

I think we did a thread about XML before, but I have more questions. What exactly do you mean by "anything can be a tag"?

It seems to me that this:

<address>
    <street_address>21 2nd Street</street_address>
    <city>New York</city> 
    <state>NY</state>
    <postal_code>10021-3100</postal_code>
</address>

Is pretty much the same as this:

  "address": {
    "street_address": "21 2nd Street",
    "city": "New York",
    "state": "NY",
    "postal_code": "10021-3100"
  },

If it branches really quickly the XML style is easier to mentally scope than brackets, though, I'll give it that.

[–] [email protected] 2 points 2 months ago* (last edited 2 months ago) (2 children)

Since XML can have attributes and children, it's not as easy to convert to JSON.

Your JSON example is more akin to:

<address street_address="21 2nd Street" city="New York" ...></address>
[–] [email protected] 3 points 2 months ago* (last edited 2 months ago) (1 children)

Hmm, so in tree terms, each node has two distinct types of children, only one of which can have their own children. That sounds more ambiguity-introducing than helpful to me, but that's just a matter of taste. Can you do lists in XML as well?

[–] [email protected] 2 points 2 months ago

No arrays are not allowed. Attributes can only be strings. But the children are kind of an array.

load more comments (2 replies)