Multiple XML Validation Scenario

Questions about XML that are not covered by the other forums should go here.
schnieders.a
Posts: 2

Multiple XML Validation Scenario

Thu Sep 26, 2013 9:47 am

Hi,

I have one XSD specifying valid DataTypes, each Datatype has a Key "ID". Another XSD is meant to uses these DataType-IDs in a KeyRef. So that the DataType-KeyRef can only contain values, that exist in a specific XML-file in the environment. How do I create a validation scenario like this? I managed to set the DataType-Key unique in the DataType-XSD. Once I create XML from the second XSD that uses the KeyRef, all fields are marked as "unique or out of scope". I assume this is because the XML defining the valid DataTypes is not taken into account. I tried the Oxygen tutorial on creating validation scenarios, but including the relevant XML file does not work. Is such validation scenario possible at all? How do I "tell" Oxygen in which XML to look for the valid values?

DataTypes.xsd

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:sdt="DataTypes.xsd"
    xmlns="DataTypes.xsd" elementFormDefault="qualified" targetNamespace="DataTypes.xsd"
    attributeFormDefault="unqualified">

    <xs:element name="DataTypes">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="DataType" type="sdt:DataTypeDef" maxOccurs="unbounded"
                    minOccurs="1"/>
            </xs:sequence>
        </xs:complexType>
        <xs:unique name="UniqueDataTypes">
            <xs:selector xpath="sdt:DataType"/>
            <xs:field xpath="sdt:ID"/>
        </xs:unique>
    </xs:element>
    <xs:complexType name="DataTypeDef">
        <xs:sequence>
            <xs:element maxOccurs="1" minOccurs="1" name="ID" type="xs:string">
                <xs:key name="DataTypeKey">
                    <xs:selector xpath="sdt:DataType"/>
                    <xs:field xpath="sdt:ID"/>
                </xs:key>
            </xs:element>
            <xs:element maxOccurs="1" minOccurs="1" name="ImplementationClass" type="xs:string"/>
        </xs:sequence>
    </xs:complexType>
</xs:schema>


The second XSD uses the KeyRef:

Code: Select all

<?xml version="1.1" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:sdt="DataTypes.xsd"
   xmlns="ClientProfile.xsd" targetNamespace="ClientProfile.xsd" xmlns:cp="ClientProfile.xsd"
   elementFormDefault="qualified">
   <xs:import namespace="DataTypes.xsd" schemaLocation="DataTypes.xsd"/>


...

Code: Select all

   <xs:complexType name="StyrisDataTypeReference">
      <xs:sequence>
         <xs:element name="DataType" type="xs:string">
            <xs:keyref name="DataProfileStyrisDataTypeKeyRef" refer="sdt:StyrisDataTypeKey">
               <xs:selector xpath="sdt:StyrisDataType"/>
               <xs:field xpath="sdt:ID"/>
            </xs:keyref>
         </xs:element>
      </xs:sequence>
   </xs:complexType>


Many thanks in advance!
AS
adrian
Posts: 2385

Re: Multiple XML Validation Scenario

Mon Oct 14, 2013 11:57 am

Hi,

You can't tell Oxygen to look for the values in a specific XML file, the schema has to do this.
If you want to validate XML files against values/content from a specific XML file, XML Schema is not a solution.
I would recommend Schematron for this specific task. In Schematron you can specify XPath functions that point to a specific XML document with the desired values.
See this article:
Validating Code Lists with Schematron
For validation against external lists look at the section Schematron and External Lists.

As for your current DataTypes.xsd schema, there's already a problem with the xs:key from the ID element. If you validate DataTypes.xsd with Saxon-EE, it will immediately point out that xs:key won't work on a simple type (it has no children) so it has to be placed in one of its ancestors.

Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
schnieders.a
Posts: 2

Re: Multiple XML Validation Scenario

Tue Oct 15, 2013 5:27 pm

Hi Adrian,

thank you very much for your reply and especially for pointing out that key-issue in my example!

I already read a bit on schematron and will probably consider it for my work.

Best regards,
Andreas
adrian
Posts: 2385

Re: Multiple XML Validation Scenario

Fri Oct 18, 2013 5:55 pm

Hi,

One last thing I'd like to point out is that you can actually use XML Schema with embedded Schematron in Oxygen.
You can find one such example in the Oxygen samples: samples/schematron/iso/tournament/Tournament.xsd

Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com

Return to “General XML Questions”

Who is online

Users browsing this forum: No registered users and 1 guest