xmlxsdxml-attribute

XML: attributes or children?


In XSD, SOAP and other XML conventions you'll often see things like:

<book>
 <title>Harry Potter</title>
 <author>J.K. Rowling</author>
</book>

Now I'm wondering, what happened to attributes? To me it makes more sense to write this as:

<book title="Harry Potter" author="J.K. Rowling" />

But apparently, for some reason, smarter people than me chose otherwise. Could someone explain why, and what attributes are for then?


Solution

  • Some people consider the difference a matter of personal preference. There are a few guidlines out there you can follow.

    W3Schools - XML Elements Vs. Attributes

    IBM - Principles of XML Design 2020 2011