xsd:为给定标签定义一个(未预定义的)属性数组

xsd: define an array of (not predefined) attributes for a given tag

我需要在 XML 中添加多种语言的本地化。 包含文本的标记称为 "saluto",目前它看起来像:

<saluto>buon giorno</saluto>

为了添加新的翻译,我能想到的最紧凑的解决方案之一是使用属性来传递不同的翻译,因此我将避免标签重复:

<saluto IT="buon giorno" EO="bonan tagon" EN="good morning" CN="早安" PL="dzień dobry" />

问题是如何编写允许执行此操作的 XSD 规则,考虑到将来可以添加新语言并且我不想更改 XSD。 可能吗?

one of the most compact solutions I can think is the use of attributes to pass the different translations, so I will avoid tag duplication

我谦虚地建议,紧凑虽然很好,但不应该是您的主要考虑因素。如果紧凑性真的是最重要的标准,那么 XML 可能是文件格式的错误选择。

The problem is how to write an XSD rule that will allow to do this, considering that in the future new languages can be added and I wouldn't like to change the XSD

如果您在 XSD 中指定了一个有效语言名称列表,那么任何 语言名称将无法根据您的 XSD 的 v1 进行验证。通常的解决方案是在出现新需求时扩展 XSD。为什么这不是您的用例的可行方法?

另一种几乎同样紧凑的方法是:

<saluto lang="EN">Good morning</saluto>

属性 lang 的允许值列表可以在简单的类型限制中指定,每种语言一个 <xs:enumeration>。 XSD 的未来版本可以简单地添加新的枚举。