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

One thing that's contrary to how XML is historically used but helps a lot.. do not use child elements where an attribute suffices:

eg, don't do this, from the article:

  <Users>
    <User>
      <FirstName>Michael</FirstName>
      <LastName>Scott</LastName>
      <FavoriteMovies>
        <Movie>Diehard</Movie>
        <Movie>Threat Level Midnight</Movie>
      </FavoriteMovies>
    </User>
    ...
  </Users>

but write it like this

  <Users>
    <User FirstName="Michael" LastName="Scott">
      <FavoriteMovies>
        <Movie Title="Diehard" />
        <Movie Title="Threat Level Midnight" />
      </FavoriteMovies>
    </User>
    ...
  </Users>  
Much easier to query for a specific element (eg, try to XPath or CSS Selector query for all of Michael Scott's favourite movies with the first syntax), and the schema is a lot easier to write and reason about

(I don't have to wonder if multiple LastNames might be allowed, if I can set a xml:lang attribute on any of them, if the ordering of FirstName and Lastname elements is constrained, etc etc)



Consider applying for YC's Summer 2026 batch! Applications are open till May 4

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

Search: