如何在 XSD 中使用 XLink 数据类型

How to use XLink data types in XSD

当我尝试使用 xjc 运行 XSD 文件时出现此错误:

Error resolving component 'xlin:href'. It was detected that 'xlin:href' is in namespace 'http://www.w3.org', but components from this namespace are not referenceable from schema document "file address" perhaps the prefix of 'xlin:href' needs to be changed. If this is the correct namespace, then an appropriate 'import' tag should be added to "file address"

代码如下:

<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
      <xs:element name="properties">
<xs:complexType>
  <xs:sequence>
    <xs:element name="property" maxOccurs="unbounded" minOccurs="0">
      <xs:complexType>
        <xs:simpleContent>
          <xs:extension base="xs:string">
            <xs:attribute type="xs:int" name="giataId" use="optional"/>
            <xs:attribute type="xs:dateTime" name="lastUpdate" use="optional"/>
            <xs:attribute ref="xlin:href" xmlns:xlin="http://www.w3.org/1999/xlink"/>
          </xs:extension>
        </xs:simpleContent>
      </xs:complexType>
    </xs:element>
  </xs:sequence>
  <xs:attribute type="xs:date" name="lastUpdate"/>
     </xs:complexType>
       </xs:element>
            </xs:schema>

要访问另一个命名空间中的任何 XSD 组件,您必须导入该命名空间。

对于你的情况,添加

<xs:import namespace="http://www.w3.org/1999/xlink" 
           schemaLocation="http://www.w3.org/1999/xlink.xsd"/>

到您的 XSD 以访问 XLink 组件。


这里是从 XSD:

中引用 href 等 XLink 组件的一般指南
  1. 声明 xlink 命名空间前缀,通常在 xs:schema 元素上:

    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
               xmlns:xlink="http://www.w3.org/1999/xlink"
    
  2. 导入 XLink XSD:

    <xs:import namespace="http://www.w3.org/1999/xlink" 
               schemaLocation="http://www.w3.org/1999/xlink.xsd"/>
    
  3. 引用所需的 XLink 组件:

    <xs:attribute ref="xlink:href" xmlns:xlin="http://www.w3.org/1999/xlink"/>