To validate an XLIFF document with the XLIFF schemas (and possible other
schemas) add the schemaLocation information in the <xliff>
start tag:
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.1 xliff.xsd" version='1.1'>
You simply need xliff.xsd at the location specified (it could be in the OASIS web site once 1.1 is published).
If you want to specify the location of several schemas, since the document might eventually contain references to various namespaces, simply enumerate the pairs namespace identifier/location:
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.1 xliff.xsd my:use-define:schema mySchema.xsd my:other:use-define:schema mySecondSchema.xsd etc..." version='1.1'>
Addition of user-define element using elements of a different namespace at specific extension points.
Here is the XML Schema definition of <group>
to allow the
inclusion of one element from another namespace (see bolded text).
<xs:complexType name="ElemType_group"> <xs:sequence> <xs:sequence> <xs:element name="context-group" type="xlf:ElemType_context-group" minOccurs="0" maxOccurs="unbounded"/> <xs:element name="count-group" type="xlf:ElemType_count-group" minOccurs="0" maxOccurs="unbounded"/> <!-- prop-group is still defined but deprected --> <xs:element name="prop-group" type="xlf:ElemType_prop-group" minOccurs="0" maxOccurs="unbounded"/> <!-- now the extension point --> <xs:any namespace="##other" processContents="lax" minOccurs="0"/> <!-- Then the rest of the definition --> <xs:element name="note" type="xlf:ElemType_note" minOccurs="0" maxOccurs="unbounded"/> </xs:sequence> etc... </xs:complexType>
This allows to insert a non-XLIFF element in the XLIFF structure:
<?xml version='1.1'?> <xliff version='1.1' xmlns="urn:oasis:names:tc:xliff:document:1.1" xmlns:myns="some_namespace_uri"> <file original='example' source-language='en' datatype='plaintext'> <body> <group> <myns:myelement>Tool-specific data</myns:myelement> <note>Some note for the translator</note> <trans-unit id='1' resname='ID_100' restype='string'> <source xml:lang='en'>Text to translate.</source> </trans-unit> </group> </body> <file> </xliff>
The added element can have child elements: any valid structure can be located there.
<?xml version='1.1'?> <xliff version='1.1' xmlns="urn:oasis:names:tc:xliff:document:1.1" xmlns:myns="some_namespace_uri"> <file original='example' source-language='en' datatype='plaintext'> <body> <group> <myns:info> <mym:data1>my data 1</mym:data1> <mym:data2>my data 2</mym:data2> </myns:info> <note>Some note for the translator</note> <trans-unit id='1' resname='ID_100' restype='string'> <source xml:lang='en'>Text to translate.</source> </trans-unit> </group> </body> <file> </xliff>
We will have to decided wether we allow only one non-XLIFF element at the
extension point, or several (by just adding maxOccurs="unbounded"
to the definition). We could also specify what specific namespace/namespaces
is/are allowed, or have a combination of both.
The mechanism is almost the same for attribute extension. We can control in which start tags we want to allow non-XLIFF attributes and if desired what namespace to allow. The only difference is that there is no control on how many can be added.
Here is the XML Schema definition for allowing an extension point in the <file>
start tag:
<xs:complexType name="ElemType_file"> <xs:sequence> <xs:element name="header" type="xlf:ElemType_header" minOccurs="0"/> <xs:element name="body" type="xlf:ElemType_body"/> </xs:sequence> <xs:attribute name="original" type="xs:string" use="required"/> <xs:attribute name="source-language" type="xs:language" use="required"/> <xs:attribute name="datatype" type="xs:string" use="required"/> <xs:attribute name="tool" type="xs:string" use="optional"/> <xs:attribute name="date" type="xs:dateTime" use="optional"/> <xs:attribute ref="xml:space" use="optional"/> <!-- ts is still there, but deprecated --> <xs:attribute name="ts" type="xs:string" use="optional"/> <!-- Than the definition of the extension point --> <xs:anyAttribute namespace="##other" processContents="lax"/> <xs:attribute name="category" type="xs:string" use="optional"/> <xs:attribute name="target-language" type="xs:language" use="optional"/> <xs:attribute name="product-name" type="xs:string" use="optional"/> <xs:attribute name="product-version" type="xs:string" use="optional"/> <xs:attribute name="build-num" type="xs:string" use="optional"/> </xs:complexType>
This will allow to have for example:
<?xml version='1.0'?> <xliff xmlns="urn:oasis:names:tc:xliff:document:1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.1 xliff.xsd" version='1.1' xmlns:myns1="some_namespace_uri" xmlns:myns2="some_other_namespace_uri"> <file original='example' source-language='en' datatype='plaintext' myns1:ctx="123" myns2:root="C:\Projects\Emerald" > <body> <group> <note>Some note for the translator</note> <trans-unit id='1' resname='ID_100' restype='string'> <source xml:lang='en'>Text to translate.</source> </trans-unit> </group> </body> </file> </xliff>
If necessary the user can choose to validate its elements/attributes by defining its own XSD file. Isolated element and attribute can be easily defined as in the following example:
<?xml version="1.0"?> <xsd:schema targetNamespace="myNamespace" xmlns:myns="myNamespace" xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified"> <xsd:attribute name="ctx" type="xsd:integer"/> <xsd:element name="myData"> <xsd:complexType> <xsd:sequence maxOccurs="unbounded"> <xsd:element name="reference" type="xsd:string" /> </xsd:sequence> <xsd:attribute name="root" type="xsd:string"/> </xsd:complexType> </xsd:element> </xsd:schema>
Such schema would allow the following XLIFF document to be valid:
<?xml version='1.0'?> <xliff xmlns="urn:oasis:names:tc:xliff:document:1.1" xmlns:myns="myNamespace" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.1 xliff.xsd myNamespace myNamespace.xsd" version='1.1'> <file original='example' source-language='en' datatype='plaintext' myns:ctx="123"> <body> <group> <myns:myData root="some text"> <myns:reference>data</myns:reference> </myns:myData> <note>Some note for the translator</note> <trans-unit id='1' resname='ID_100' restype='string'> <source xml:lang='en'>Text to translate.</source> </trans-unit> </group> </body> </file> </xliff>