Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

1. Why is parsing a tree which is encoded in JSON easier? 2. Why does it matter if an element is in an attribute or in child elements. You need some kind of schema anyway, right?


It depends on the API of the system. I’ve worked on middleware that would not be able to get an attribute, it lacked the capability. Other systems used JavaScript and it was much easier with JSON

See this link on stack exchange[1].

[1] https://stackoverflow.com/questions/17604071/parse-xml-using...

> //Gets Street name xmlDoc.getElementsByTagName("street")[0].childNodes[0].nodeValue;

I’d much prefer something like jsonObj.address[0].street;. Personally I like to work with objects over parsing documents trees.


The author makes a case for why it would matter:

> XML, on the other hand, optimizes for document tree structures, by cleanly separating node data (attributes) from child data (elements).

Unfortunately, there appear to be some implementation issues here. You have to create a string version of your data to store them in attributes.

So, you lose a bit of context in the conversion.

Such as:

`<Document text="true" />`

Is the text attribute the word _true_ or a boolean _true_. Without referencing some other piece of code or definition there is no way to know.

Whereas in JSON, this wouldn't be necessary, as you can simply remove the quotes and infer that it is not a string, but a boolean.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: