XML: attributes or children? [duplicate]

安稳与你 提交于 2019-12-02 02:33:37

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

There's no hard and fast rule. I tend to use attributes for metadata about the data contained in the elements. e.g

<book author="JK Rowling" published="September 2001">Harry Potter</book>

although usage/particular requirements will determine this more than anyrhing else.

Another issue is the subsequent processing. If you're using a SAX processor then this format will result in one method callback with the atteribute structure populated. Putting the data in multiple elements will result in the corresponding number of method calls (this may be an optimisation too far, but it may be worth considering depending on the quantity of data)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!