【问题标题】:Require (allow) "xml:base"-attribute in XML Schema在 XML Schema 中需要(允许)“xml:base”-attribute
【发布时间】:2012-04-20 06:59:59
【问题描述】:

给定一个文件,如下所示:

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

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

如何编写 XML Schema 以要求(甚至允许)在 &lt;patch&gt; 上存在固定值为“http://example.com/publ/lxfs”的 xml:base 属性?

这是我认为“显而易见”的解决方案,但 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>

【问题讨论】:

    标签: xml xsd


    【解决方案1】:

    &lt;xs:attribute name="xml:base"&gt; 更改为&lt;xs:attribute ref="xml:base"&gt;,并为可在http://www.w3.org/2001/03/xml.xsd 找到的XML 命名空间的模式添加xs:import。 (使用本地副本而不是参考 W3C 上的副本

    【讨论】:

      【解决方案2】:

      为了澄清 Michael 已经发布的内容,为了解决这个问题,我首先将这一行添加到我的架构顶部:

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

      然后要将它附加到元素上,只需添加属性:

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

      哇,这让我省了很多麻烦。

      【讨论】:

        猜你喜欢
        • 2021-03-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-10-18
        • 1970-01-01
        • 2011-05-22
        • 1970-01-01
        相关资源
        最近更新 更多