Search code examples
phpxmlxsdxsd-validationxml-validation

How to validate ids between XML documents in XSD?


I'm trying to make a cross platform string management system, for both iOS and Android app (so I don't have to translate both app and I reuse string from one app into the other).

For this, I use the following flow :

  1. XML storing cross platform string identifiers (with potentially attributes like comment or iOS-only, ...)

    <!-- identifiers.xml -->
    <identifiers>
       <id>button_signin_facebook</id>
       <id ios-only="true">button_signin_apple</id>
       ...
    </identifiers>
    
  2. And then I have N translations for the N supported languages :

    <!-- translation_en.xml -->
    <translation lang="en">
      <string id="button_signin_facebook">Continue with Facebook</string>
      <string id="button_signin_apple">Continue with Apple ID</string>
      ...
    </translation>
    

A PHP script processes all of this and generate all translation files for both platform, after verifying integrity (see if some string are unused, see if we have created a string twice etc.)

Now my question is : How to make a XSD for the translation_lang.xml files enforcing that the id attribute of string elements is a "enumeration" (or "reference" ?) from all the id in the identifiers.xml file ? (just like a foreign key in a database)

I'm new to XSD, and I found that I could make enumeration in XSD, but it's not what I want. (The identifiers values needs to be in the XML file identifiers.xml and not in a schema, because they are not fixed.)


Solution

  • XSD cannot express constraints between separate XML documents.

    Alternative possibilities:

    1. Write the cross-document validation constraints in XSLT, PHP, or another language.
    2. Combine the separate XML documents into a single composite XML document for purposes of validating via XSD.