2011-04-30 38 views
4

給定一個文件,如以下幾點:要求(允許)「的xml:基地」的XML Schema -attribute

<patch xmlns="http://example.com/ns/lxfs" 
     xml:base="http:/example.com/publ/lxfs" 
     id="http://example.com/lxfs/patches/3"> 

    <!-- ... --> 
</patch> 

如何編寫一個XML Schema要求(甚至允許)的存在​​屬性與<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> 

回答

3

變化<xs:attribute name="xml:base"><xs:attribute ref="xml:base">,並添加一個xs:進口的模式爲XML命名空間,其可以在http://www.w3.org/2001/03/xml.xsd找到。 (使用本地副本,而不是參照一個在W3C

1

只是爲了澄清什麼邁克爾已經發布,來解決這個問題,我首先加入這一行到我的架構的頂部:

<xs:import namespace="http://www.w3.org/XML/1998/namespace" 
      schemaLocation="http://www.w3.org/2001/03/xml.xsd" /> 

然後到這個附加到元素,只需添加屬性:

<xs:attribute ref="xml:base" /> 

哇,這救了我很多頭疼的