Riley van Hengstum
Riley van Hengstum

Reputation: 4552

How to use xml:lang in xsd/xml?

I have the following XSD:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns="http://www.vibrogym.com/schema"
        xmlns:xs="http://www.w3.org/2001/XMLSchema"
        targetNamespace="http://www.vibrogym.com/schema"
        elementFormDefault="qualified" >

    <xs:import schemaLocation="http://www.w3.org/2001/xml.xsd" 
               namespace="http://www.w3.org/XML/1998/namespace"/>

    <xs:complexType name="localizedNameType">
        <xs:simpleContent>
            <xs:extension base="xs:string">
                <xs:attribute ref="xml:lang" use="required"/>
            </xs:extension>
        </xs:simpleContent>
    </xs:complexType>

    <xs:element name="exercise">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="name" 
                            type="localizedNameType" 
                            minOccurs="1" 
                            maxOccurs="unbounded"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>

</xs:schema>

And the following XML:

<?xml version="1.0" encoding="UTF-8"?>
<exercise xmlns="http://www.vibrogym.com/schema">
    <name xml:lang="en">test</name>
</exercise>

PHPStorm gives the following validation error: Element name doesn't have the required attribute lang.

Is PHPStorm correct in giving me the validation error? If so, what am I doing wrong?

UPDATE

Apparently the use="required" attribute on localizedNameType type triggers the validation error; Why is this wrong?

Upvotes: 1

Views: 1341

Answers (1)

C. M. Sperberg-McQueen
C. M. Sperberg-McQueen

Reputation: 25044

No, PHPStorm is not correct; the document is valid against the schema you give. As kjhughes has speculated, the problem may be related to errors in its treatment of the xml namespace. If adding the namespace declaration he suggests causes PHPStorm to accept the document, then you have two bugs to report: the failure to validate this example correctly, and failure to report a namespace well formedness error on the version with a namespace declaration for the xml namespace. (The prefix xml is reserved, so you're not allowed to declare a namespace with prefix xml.)

Upvotes: 2

Related Questions