未限定的 XSD 全局属性引用 [英] Unqualified XSD global attribute references

查看:27
本文介绍了未限定的 XSD 全局属性引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下 XML 架构无法使用以下 XML 实例文档进行验证.有什么方法可以重写架构,以便在给定的约束内验证实例文档?

The following XML schema fails to validate with following XML instance document. Is there any way to rewrite the schema so the instance document validates, within the given constraints?

  • 该属性不能是元素的本地属性
  • 实例文档必须保持不变
<?xml version="1.0" encoding="utf-8"?>
<xs:schema targetNamespace="http://tempuri.org/XMLSchema.xsd"
    elementFormDefault="qualified"
    xmlns="http://tempuri.org/XMLSchema.xsd"
    xmlns:xs="http://www.w3.org/2001/XMLSchema">

    <xs:attribute name="sample-attribute" type="xs:string" />

    <xs:element name="sample-element">
        <xs:complexType>
            <xs:attribute ref="sample-attribute" use="required" />
        </xs:complexType>
    </xs:element>
</xs:schema>

实例

<?xml version="1.0" encoding="utf-8"?>
<sample-element xmlns="http://tempuri.org/XMLSchema.xsd" sample-attribute="test" />

推荐答案

命名空间在 XML 中 指出无前缀属性名称的命名空间名称始终没有值";另一方面,您将属性限制为不是本地的,因此唯一的方法(归功于@GrahamHannington) 是将其包装在一个属性组中,从而允许属性定义为不合格就重复使用.

Namespaces in XML states that "The namespace name for an unprefixed attribute name always has no value"; on the other hand you constrained the attribute not to be local, so the only way to do it (credit goes to @GrahamHannington) is to wrap it in an attribute group, thus allowing the attribute definition to be reused without being qualified.

这篇关于未限定的 XSD 全局属性引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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