Malax
Malax

Reputation: 9614

How to allow xml:lang attribute in XMLSchema?

I want to allow the use of xml:lang attributes in some of my element of my XMLSchema. But i can't find anything which describes how to to it.

Upvotes: 7

Views: 9270

Answers (2)

Christopher Schultz
Christopher Schultz

Reputation: 20862

You have to do a bit of hunting to piece this together from the standards. Here's the magic sauce you need in order to allow xml:lang attributes on your XML elements.

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <!-- Import xml: namespace -->
  <xs:import namespace="http://www.w3.org/XML/1998/namespace"
        schemaLocation="https://www.w3.org/2009/01/xml.xsd" />

  <!-- ... --->

  <xs:complexType name="myLanguagedElement">
    <!-- ... -->

    <!-- use ref="" instead of name="", here in your attribute -->
    <xs:attribute ref="xml:lang" use="optional" /><!-- or "required" if you like -->
  </xs:complexType>
</xs:schema>

Edit: The new schemaLocation changed to https://www.w3.org/2009/01/xml.xsd

Upvotes: 5

olek
olek

Reputation: 304

You can either create your own attribute with xmlschema type language, or reference xml:lang attribute as in the example Import another XML schema. I hope this will help.

Upvotes: 4

Related Questions