1

I have an XML document with language specific elements, example:

<root lang="en fr">
    <section>
        <title lang="en">English Title</title>
        <title lang="fr">French Title</title>
        <sequence>2</sequence>
        <field>
           <type>date</type> 
           <label lang="en">English field label</label>
           <label lang="fr">French field label</label>
        </field>
    </section>
    <section>
        <title lang="en">Another English Title</title>
        <title lang="fr">Another French Title</title>
        <sequence>1</sequence>
    </section>
</root>

At the top, the root element is intended to declare the document defines both english and french information.

There are certain elements in the document that need to be provided in english and french, such as title and label , since the root element declares support for both.

Is it possible to to express such a constraint in XML Schema? I could express the root element language attribute differently, such as lang-en="1" lang-fr="1" if that helps.

kjhughes
  • 106,133
  • 27
  • 181
  • 240
yas
  • 3,520
  • 4
  • 25
  • 38

1 Answers1

0

In XSD 1.0, you cannot represent such a constraint.

In XSD 1.1, you can use xsd:assert, but it would have to be at the root level. See How to access parent element in XSD assertion XPath? for an example of how to make an assertion using an every..in..satisfies XPath 2.0 expression.

See also for general i18n in XML design considerations: xml:lang in XML document schemas

kjhughes
  • 106,133
  • 27
  • 181
  • 240
  • You might (just) be able to use XSD 1.1 inheritable attributes here. By defining the root/@lang attribute as inheritable, it becomes available for use in a conditional type assignment on elements further down the tree. But looking at the detail, I'm not sure it's flexible enough for this use case. – Michael Kay Jul 26 '16 at 14:41