XML:属性还是子级? [英] XML: attributes or children?

查看:92
本文介绍了XML:属性还是子级?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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?

推荐答案

有些人认为差异与个人喜好有关.您可以遵循一些指南.

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

W3Schools-XML ElementsVs.属性

IBM-XML设计原理

这篇关于XML:属性还是子级?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆