gpt4 book ai didi

xml - XML 数据和 XML 元数据之间有什么区别?

转载 作者:数据小太阳 更新时间:2023-10-29 02:05:44 30 4
gpt4 key购买 nike

我正在重建一些 XML 提要,因此我正在研究何时使用元素以及何时使用带有 XML 的属性。

一些网站说“数据在元素中,元数据在属性中。”

那么,两者有什么区别呢?

让我们以 W3Schools 为例:

<note date="12/11/2002">
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>

日期应该保留为 note 元素的属性吗?还是进入它自己的元素更有意义?

<date>12/11/2002</date>

或者,将它分成多个元素有意义吗?

<date>
<day>12</day>
<month>11</month>
<year>2002</year>
</date>

最佳答案

按照“数据在元素中,元数据在属性中。”,我会把日期设为子元素。您不需要将其分解为日、月和年,因为我认为实际上有一种方法可以在 XSD 中指定元素必须是 Date 类型。我认为此处“元数据”的一个示例是 noteID 字段或 noteType。示例:

<note id="NID0001234" type="reminder">
<date>2002-11-12</date>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>

更新:正如许多其他人指出的那样,它可能相当主观。我试图通过它们的使用方式来区分两者。数据通常会呈现给用户,元数据将控制呈现并可能在内部用于其他目的。但总有异常(exception)...

关于xml - XML 数据和 XML 元数据之间有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4206765/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com