不合格的 XSD 全局属性引用 [英] Unqualified XSD global attribute references

查看:15
本文介绍了不合格的 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天全站免登陆