如何验证 XSD 中的语言属性? [英] How to validate for language attributes in XSD?

查看:26
本文介绍了如何验证 XSD 中的语言属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含特定语言元素的 XML 文档,例如:

I have an XML document with language specific elements, example:

<root lang="en fr">
    <section>
        <title lang="en">English Title</title>
        <title lang="fr">French Title</title>
        <sequence>2</sequence>
        <field>
           <type>date</type> 
           <label lang="en">English field label</label>
           <label lang="fr">French field label</label>
        </field>
    </section>
    <section>
        <title lang="en">Another English Title</title>
        <title lang="fr">Another French Title</title>
        <sequence>1</sequence>
    </section>
</root>

在顶部,根元素旨在声明文档定义了英语和法语信息.

At the top, the root element is intended to declare the document defines both english and french information.

文档中的某些元素需要以英文和法文提供,例如 titlelabel ,因为根元素声明了对两者的支持.

There are certain elements in the document that need to be provided in english and french, such as title and label , since the root element declares support for both.

是否可以在 XML Schema 中表达这样的约束?我可以用不同的方式表达 root 元素的语言属性,例如 lang-en="1" lang-fr="1" 如果有帮助的话.

Is it possible to to express such a constraint in XML Schema? I could express the root element language attribute differently, such as lang-en="1" lang-fr="1" if that helps.

推荐答案

在 XSD 1.0 中,您不能表示这样的约束.

In XSD 1.0, you cannot represent such a constraint.

在 XSD 1.1 中,您可以使用 xsd:assert,但它必须在 root 级别.请参阅如何访问 XSD 断言 XPath 中的父元素? 了解如何制作使用 every..in..satisfies XPath 2.0 表达式的断言.

In XSD 1.1, you can use xsd:assert, but it would have to be at the root level. See How to access parent element in XSD assertion XPath? for an example of how to make an assertion using an every..in..satisfies XPath 2.0 expression.

另请参阅 XML 设计注意事项中的一般 i18n:xml:lang在 XML 文档模式中

See also for general i18n in XML design considerations: xml:lang in XML document schemas

这篇关于如何验证 XSD 中的语言属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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