4 ms·
I don't disagree that JSON is better than XML for their "list" example,and that XML is better than JSON for their "UI layout" example. BUT: > This means there’
by jrochkind1 7y ago
I don't disagree that JSON is better than XML for their "list" example,and that XML is better than JSON for their "UI layout" example. BUT:
> This means there’s no officially supported way to represent the list of movies in an element attribute. We can hack this by encoding the list into an attribute using a comma delimiter:
<Users>
<User
first="Michael"
last="Scott"
favoriteMovies="Diehard, Threat Level Midnight" />
So, that's because you're doing it wrong. XML has NO PROBLEM with hieararchy, REALLY. Of COURSE there's a supported way to encode hieararchy.
<Users>
<User>
<first>Michael</first>
<last>Scott</last>
<favoriteMovies>
<title>Diehard</title>
<title>Threat Level Midnight</title>
</favoriteMovies>
</User>
- shawabawa3 7y agoYou should have read the next paragraph. They do use that as an example <Users> <User> <FirstName>Michael</FirstName> <LastName>Scott</LastName> <FavoriteMovies> <Movie>Diehard</Movie> <Movie>Threat Level Midnight</Movie> </FavoriteMovies> </User>
- jrochkind1 7y agoFair! Why the heck did the author first try to tell us XML had no "officially supported way" to do this then?
- Slartie 7y agoBecause it was about encoding a list of things in an _attribute_. Attribute! Using nested elements is not exactly a solution for that requirement.
- wtetzner 7y agoAnd if you want, you can still keep some of the attributes: <Users> <User first="Michael" last="Scott"> <favoriteMovies> <title>Diehard</title> <title>Threat Level Midnight</title> </favoriteMovies> </User>