如何在XML Schema中声明xml:lang属性?

时间:2015-06-04 10:45:37

标签: xml xsd

我试图在XML Schema中为以下示例实例声明一个xml:lang属性:

<?xml version="1.0" encoding="UTF-8"?>
<database xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="xml-lang-1.xsd">
    <entry>
        <language xml:lang="en">
            <other_data/>
        </language>
        <language xml:lang="nl">
            <other_data/>
        </language>
    </entry> 
</database>

目前,我有两个解决方案:

  1. 使用:

    <xs:attributeGroup name="XMLNamespaceAttrs">
      <xs:anyAttribute namespace="http://www.w3.org/XML/1998/namespace" processContents="lax"/>
    </xs:attributeGroup>
    
  2. 在同一架构中,或

    1. 使用xs:import并导入:

      <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://www.w3.org/XML/1998/namespace">
         <xs:import schemaLocation="xml-lang-2.xsd"/>
         <xs:attribute name="lang" type="xs:NCName"/>
      </xs:schema>
      
    2. 来自外部文件。

      我的问题:

      • 还有其他方法可以在XML Schema中声明xml:lang属性吗?
      • 如何将use属性与xml:lang属性相关联?在上面的示例中,不允许使用use属性 xs:anyAttribute(解决方案1)和xs:属性(解决方案2)。
      • 以上示例中xml:lang的数据类型是否隐含为xs:languag e(或其他),或者需要这样做/可以是 明确宣布?

      非常感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

我认为以最有效的方式在XML命名空间中声明属性是第一个选项:首先,在将XML的命名空间作为目标命名空间的不同模式中声明属性,然后将import此模式转换为您的主架构和ref您要使用的属性。这样,您可以使用use属性以及XML的架构属性。