如何将相同的属性多次添加到 XML 中的元素标记 [英] How to add the same attribute multiple times to an Element Tag in XML

查看:44
本文介绍了如何将相同的属性多次添加到 XML 中的元素标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我正在编写的 XML 架构 (XSD) 中,我需要定义一个属性,该属性可以在其父元素内多次出现.

In an XML Schema (XSD) I am writing, I need to define an attribute which can occur multiple times inside its parent element.

举个例子来说明一下:父元素代表事件,它支持不同的属性,例如标题和发生日期.称为department 的属性之一是组织部门.一项活动可能由一个或多个部门组织.

Just to clear it with an example : the parent element represent events, and it supports different attributes like a title and an occurrence date for instance. One of the attributes called department is the organizing department. An event may be organized by one, or many departments.

我想知道 XSD 是否可以处理一个元素中同一属性的多个实例,或者这是否超出了 XML 标准的范围?

I want to know if XSD can handle multiple instances of the same attribute in an element or if this is beyond the scope of XML Standard ?

推荐答案

你不能.每个元素的属性名称都是唯一的.

You can't. Attribute names are unique per element.

如果您需要在同名下有多位数据,那么通常的解决方案是使用空格分隔的列表或子元素.

If you need to have multiple bits of data under the same name, then the usual solutions are either a space separated list or child elements.

<event department="foo bar baz" />

<event>
    <department>foo</department>
    <department>bar</department>
    <department>baz</department>
</event>

这篇关于如何将相同的属性多次添加到 XML 中的元素标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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