Re: Defining Xlinks in XMLschema

C Baines posted:

>I have not seen anything about defining xlinks in XMLschema.

to www-xml-linking-comments@w3.org
located at
http://lists.w3.org/Archives/Public/www-xml-linking-comments/2003AprJun/0012
.html
on Tue, May 13 2003

Neither had I so I created a working version (for traditional/validating
parsers) of XLink Schema based on the W3C note describing what might be
called Schema-XLink: http://www.w3.org/TR/xlink-naming/#datatypes

<!-- BOF name="xlink.xsd" -->
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE schema PUBLIC "-//W3C//DTD XMLSCHEMA 200010//EN"
"http://www.w3.org/2000/10/XMLSchema.dtd">
<schema id="xlink.xsd" targetNamespace="XLINK"
xmlns="http://www.w3.org/2001/XMLSchema" xmlns:xl="XLINK">
    <attribute name="type">
        <simpleType>
            <restriction base="NMTOKEN">
                <enumeration value="simple"/>
                <enumeration value="extended"/>
                <enumeration value="locator"/>
                <enumeration value="arc"/>
                <enumeration value="resource"/>
                <enumeration value="title"/>
                <enumeration value="none"/>
            </restriction>
        </simpleType>
    </attribute>
    <attribute name="href">
        <simpleType>
            <restriction base="anyURI"/>
        </simpleType>
    </attribute>
    <attribute name="role">
        <simpleType>
            <restriction base="anyURI"/>
        </simpleType>
    </attribute>
    <attribute name="arcrole">
        <simpleType>
            <restriction base="anyURI"/>
        </simpleType>
    </attribute>
    <attribute name="title">
        <simpleType>
            <restriction base="normalizedString"/>
        </simpleType>
    </attribute>
    <attribute name="show">
        <simpleType>
            <restriction base="NMTOKEN">
                <enumeration value="new"/>
                <enumeration value="replace"/>
                <enumeration value="embed"/>
                <enumeration value="other"/>
                <enumeration value="none"/>
            </restriction>
        </simpleType>
    </attribute>
    <attribute name="actuate">
        <simpleType>
            <restriction base="NMTOKEN">
                <enumeration value="onLoad"/>
                <enumeration value="onRequest"/>
                <enumeration value="other"/>
                <enumeration value="none"/>
            </restriction>
        </simpleType>
    </attribute>
    <attribute name="label">
        <simpleType>
            <restriction base="NMTOKEN"/>
        </simpleType>
    </attribute>
    <attribute name="from">
        <simpleType>
            <restriction base="NMTOKEN"/>
        </simpleType>
    </attribute>
    <attribute name="to">
        <simpleType>
            <restriction base="NMTOKEN"/>
        </simpleType>
    </attribute>
</schema>
<!-- EOF -->

You may notice that it does not include the ability to allow a single
element to describe multiple links. There are two proposed solutions to this
problem in the note but they seemed too preliminary.

In any case, the schema above would allow you to create your own schema that
imports it so that you can markup elements with xlink namespaced attributes
as in the following example:

<!-- BOF name="testXlink.xsd" -->
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema id="testXlink.xsd" xmlns:xl="XLINK"
xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
attributeFormDefault="unqualified">
    <xs:import namespace="XLINK" schemaLocation="xlink.xsd"/>
    <xs:element name="test">
        <xs:complexType>
            <xs:attribute ref="xl:type"/>
            <xs:attribute ref="xl:href"/>
            <xs:attribute ref="xl:role"/>
            <xs:attribute ref="xl:arcrole"/>
            <xs:attribute ref="xl:title"/>
            <xs:attribute ref="xl:show"/>
            <xs:attribute ref="xl:actuate"/>
            <xs:attribute ref="xl:label"/>
            <xs:attribute ref="xl:from"/>
            <xs:attribute ref="xl:to"/>
        </xs:complexType>
    </xs:element>
</xs:schema>
<!-- EOF -->

The end result is your instance document can appear as XLink specifies and
still be validated with traditional parsers as demonstrated below:

<!-- BOF name="testInstance.xml" -->
<?xml version="1.0" encoding="UTF-8"?>
<test xmlns:xl="XLINK" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="testXlink.xsd"
    xl:type="simple"
    xl:href="http://www.w3.org/TR/xlink-naming/"
    xl:title="Test this link to W3C Note: XLink Markup Name Control"
    xl:show="new"
    xl:actuate="onRequest"
    xl:role="http://www.w3.org/TR" />
<!-- EOF -->

Rein

Received on Thursday, 17 July 2003 03:05:53 UTC