在 XML Schema 中为不同的命名空间声明一个属性 [英] Declaring an attribute for a different namespace in XML Schema

查看:21
本文介绍了在 XML Schema 中为不同的命名空间声明一个属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用混合不同现有格式和一些自定义元素和属性的 XML 格式,我认为我应该为这些自定义位编写一个架构.

I've been using an XML format that is a mix of different existing formats and some custom elements and attributes, and I thought I should write a schema for those custom bits.

我做的一件事是在现有格式的元素上使用自定义属性,如下所示:

One thing I do is use custom attributes on elements in existing formats, like this:

<ns1:something attA="b" attB="a" ns2:extraAtt="c"/>

我知道这样做是允许的,但我不知道如何在 XML Schema 或更糟的 DTD 中声明我的extraAtt".

I understand that doing this is allowed but I cannot think how to declare my "extraAtt" in XML Schema or, worse, in a DTD.

我曾尝试阅读规范,但也可以这样写就我而言,是中文.大多数教程只讨论名称"、类型"和使用",例如这个那个.

I have tried reading the specification, but it could just as well be written in Chinese as far as I am concerned. Most tutorials talk only about "name", "type", and "use", e.g. this one and that one.

推荐答案

每个架构文档为一个命名空间定义组件(架构的一部分).因此,要定义您的属性 ns2:extraAtt,您需要一个类似于以下内容的架构文档:

Each schema document defines components (pieces of a schema) for one namespace. So to define your attribute ns2:extraAtt you want a schema document something like this one:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
  targetNamespace="http://example.com/my-ns2">
  <xs:attribute name="extraAtt" type="xs:anySimpleType"/>
</xs:schema>

元素 ns1:something 的声明需要以某种方式允许此属性,或者使用属性引用 (<xs:attribute ref="ns2:extraAtt"/>) 或使用属性通配符( 或类似的).

The declaration of element ns1:something will need to allow for this attribute somehow, either with an attribute reference (<xs:attribute ref="ns2:extraAtt"/>) or with an attribute wildcard (<xs:anyAttribute namespace="http://example.com/my-ns2"/> or similar).

抱歉规范的易读性;说来话长,但基本上 WG 的一些成员并不认为像你这样的人存在(除了实现者,没有人会阅读规范,只要他们不抱怨它就足够可读"——至少,这就是他们在一些实施者确实抱怨之前说,大声而痛苦地;然后他们只是转移了话题).

Sorry about the legibility of the spec; it's a long story, but essentially some members of the WG did not think people like you exist ("no one except implementors reads the spec, and as long as they don't complain it's readable enough" -- at least, that was what they said before some implementors did complain, loudly and bitterly; then they just changed the subject).

这篇关于在 XML Schema 中为不同的命名空间声明一个属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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