How to reuse elements from another Schema / Namespace (i.e. XHTML) with XML Schema?

前端 未结 1 1707
情歌与酒
情歌与酒 2021-01-23 19:10

I\'m trying to define a Schema which allows the use of specific (X)HTML elements in certain places. The problem that I\'m facing is that the Schema fails compiling.

Here

相关标签:
1条回答
  • 2021-01-23 19:52

    It seems that the "blockquote" element is not defined as global element, thus you can not refer to it directly. If you have a look in the sub part of the xhtml schema http://www.w3.org/MarkUp/SCHEMA/xhtml11-model-1.xsd, you can notice that its type is xhtml.blockquote.type.

    So a workaround would be to declare your blockquote like so :

    <xs:schema xmlns:html="http://www.w3.org/1999/xhtml" xmlns:xs="http://www.w3.org/2001/XMLSchema">
        <xs:import namespace="http://www.w3.org/1999/xhtml" schemaLocation="http://www.w3.org/MarkUp/Schema/xhtml11.xsd"/>
            <xs:element name="foo">
            <xs:complexType>
                <xs:sequence>
                    <xs:element name="blockquote" type="html:xhtml.blockquote.type" minOccurs="0" maxOccurs="unbounded"/>
                </xs:sequence>
            </xs:complexType>
        </xs:element>
    </xs:schema>
    

    along with this valid XML instance:

    <?xml version="1.0"?>
    <foo xmlns:html="http://www.w3.org/1999/xhtml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="test.xsd">
        <blockquote><html:p>quick brown fox jumped over the lazy dog.</html:p></blockquote>
    </foo>
    

    You will notice that the blockquote element is not bound to the html namespace. Since you import other namespace's elements, I think also it would be a better practice to set a default target namespace to your own elements.

    0 讨论(0)
提交回复
热议问题