给定如下文档:
<patch xmlns="http://example.com/ns/lxfs"
xml:base="http:/example.com/publ/lxfs"
id="http://example.com/lxfs/patches/3">
<!-- ... -->
</patch>
如何编写XML Schema来要求(甚至允许)xml:base
属性在<patch>
上具有固定值"http://example.com/publ/lxfs"?
这是我认为"明显"的解决方案,但xs:attribute[@name]
应该是NCName
:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:lxfs="http://example.com/ns/lxfs"
xmlns:xml="http://www.w3.org/XML/1998/namespace"
targetNamespace="http://example.com/ns/lxfs">
<xs:element name="patch" type="lxfs:Patch" />
<xs:complexType name="Patch">
<xs:attribute name="id" type="xs:anyURI" use="required" />
<xs:attribute name="xml:base" form="qualified" fixed="http://example.com/publ/lxfs" use="required" />
</xs:complexType>
</xs:schema>
将<xs:attribute name="xml:base">
更改为<xs:attribute ref="xml:base">
,并为可在http://www.w3.org/2001/03/xml.xsd
中找到的XML命名空间的模式添加xs:import。(使用本地副本而不是引用W3C
为了澄清Michael已经发布的内容,为了解决这个问题,我首先在schema的顶部添加了这一行:
<xs:import namespace="http://www.w3.org/XML/1998/namespace"
schemaLocation="http://www.w3.org/2001/03/xml.xsd" />
然后将其附加到元素,只需添加属性:
<xs:attribute ref="xml:base" />