XML:属性还是孩子?

Bar*_*lom 2 xml xsd xml-attribute

在XSD,SOAP和其他XML约定中,您经常会看到以下内容:

<book>
 <title>Harry Potter</title>
 <author>J.K. Rowling</author>
</book>
Run Code Online (Sandbox Code Playgroud)

现在我想知道,属性发生了什么?对我而言,将其写为:

<book title="Harry Potter" author="J.K. Rowling" />
Run Code Online (Sandbox Code Playgroud)

但显然,出于某种原因,比我聪明的人选择了其他方式.有人可以解释为什么,那么属性是什么?

Jus*_*ner 5

有些人认为差异是个人偏好的问题.您可以遵循一些指导原则.

W3Schools - XML元素比.属性

IBM - XML设计原理