Skip to main content
XMLDir

Search 261 pages — tools, formats, elements, namespaces, XPath, datatypes, glossary, parse errors, schema errors, use cases, blog and product.

XSD datatype

xs:language

A BCP 47 language tag, checked by shape rather than against the registry.

xs:language accepts tags of the form used by xml:lang — a primary subtag of letters, optionally followed by hyphen-separated subtags. Validation is a pattern check on the structure.

Nothing verifies the tag actually exists. 'zz-ZZ' is a valid xs:language and refers to no language at all.

Lexical space
1–8 letters, then any number of hyphen-separated 1–8 alphanumeric subtags.
Derives from
xs:token
Category
String types
Facets
length, minLength, maxLength, pattern, enumeration, whiteSpace

What validates

Every literal below is put through the schema validator on each test run, against the schema at the foot of this page.

  • en
  • en-GB
  • de-CH-1901
  • zz-ZZ
  • english
  • e

What does not

  • en_GB

    Subtags are separated by hyphens, not underscores.

  • 123

    The primary subtag must be letters, not digits.

  • en-

    A trailing hyphen leaves an empty subtag.

What catches people out

  • The tag is checked for shape, not existence. Invented tags validate.
  • Underscores are not separators. 'en_GB' fails where 'en-GB' passes.
  • Case is not normalised, so 'EN-gb' and 'en-GB' are different strings to an enumeration.

The schema used

This is the exact schema the literals above are validated against. Paste it into the validator with one of them to see the result yourself.

schema.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="v" type="xs:language"/>
</xs:schema>

Open the XSD validator

Related

All 29 datatypes and facets

Get started

Bring order to the XML your team can't afford to ignore.

Create a free account and get a private workspace to search, validate, diff, and monitor your XML feeds, sitemaps, schemas, and vendor integrations.