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

时间:2013-11-04 21:13:30

标签: xml xsd xlink

我想定义能够链接其中图像的XML。我发现XLink可以实现。但我找不到如何导入/包含正确的XSD。

以下XSD无法验证:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:xlink="http://www.w3.org/1999/xlink"
    xmlns="http://www.inthemoon.ru/2013/Celebrity"

    targetNamespace="http://www.inthemoon.ru/2013/Celebrity">

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

    <xs:element name="celebrities">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="celebrity" minOccurs="0" maxOccurs="unbounded">
                    <xs:complexType>
                        <xs:all>
                            <xs:element name="names">
                                <xs:complexType>
                                    <xs:sequence>
                                        <xs:element maxOccurs="unbounded" name="name"
                                            type="xs:string"/>
                                    </xs:sequence>
                                    <xs:attribute name="lang" type="xs:string"/>
                                </xs:complexType>
                            </xs:element>
                            <xs:element name="images">
                                <xs:complexType>
                                    <xs:sequence>
                                        <xs:element name="image">
                                            <xs:complexType>
                                                <xs:attribute name="href" type="xlink:href"/>
                                            </xs:complexType>
                                        </xs:element>
                                    </xs:sequence>
                                </xs:complexType>
                            </xs:element>
                        </xs:all>
                    </xs:complexType>
                </xs:element>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>

1 个答案:

答案 0 :(得分:2)

使用<xs:attribute ref="xlink:href"/>