Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to allow xml:lang attribute in XMLSchema?

Tags:

xml

xsd

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.

like image 510
Malax Avatar asked Sep 21 '11 15:09

Malax


2 Answers

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

like image 124
Christopher Schultz Avatar answered Sep 28 '22 19:09

Christopher Schultz


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.

like image 20
olek Avatar answered Sep 28 '22 19:09

olek