Question

I have some issues with XML Schema. I need to put some HTML code in my XML file and I found that xs:any would help. But xmllint return me errors like this:

example.xml:4: element h1: Schemas validity error : Element 'h1': This element is not expected. Expected is ( {http://www.w3.org/1999/xhtml}* ).

XML:

<?xml version="1.0" encoding="UTF-8"?>
<foo>
<bar>
    <h1>Lorem ipsum</h1>
</bar>
</foo>

Schema:

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="foo">
    <xs:complexType>
        <xs:sequence>
            <xs:element name="bar" minOccurs="1" maxOccurs="unbounded">
                <xs:complexType>
                    <xs:sequence>
                        <xs:any namespace="http://www.w3.org/1999/xhtml" />
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
        </xs:sequence>
    </xs:complexType>
</xs:element>
</xs:schema>

What I do wrong?

Was it helpful?

Solution

The schema says that each bar element can contain one element that is in the http://www.w3.org/1999/xhtml namespace, but in the instance document you have used an element named h1 that is in no namespace. You need to either put xmlns="http://www.w3.org/1999/xhtml" on the h1, or put a prefix declaration further up the tree (e.g. <foo xmlns:h="http://www.w3.org/1999/xhtml">) and then use that prefix on the XHTML elements (<h:h1>).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top