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

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>


You 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>


Fair! Why the heck did the author first try to tell us XML had no "officially supported way" to do this then?


Because it was about encoding a list of things in an _attribute_. Attribute! Using nested elements is not exactly a solution for that requirement.


And 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>




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

Search: