0

Sorry to reopen the case already addressed here. To aggravate my case, I am not an expert in computer science.

Taking the example given by the page linked above, it seems that most of the online XML/XSD validator reject it as invalid with the message :

s4s-elt-invalid-content.1: The content of '#AnonType_IMtypeIMtimehorizonenabler' is invalid. Element 'alternative' is invalid, misplaced, or occurs too often.

Indeed it seems that the version of XSD is critical as it is underlined that the XSD code must explicitly stipulate:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning"  elementFormDefault="qualified" vc:minVersion="1.1"> 

My question is therefore the following:

  • Did I missed something OR
  • online validators does not support this vc:minVersion="1.1" prescription

My own XML file:

<?xml version="1.0" encoding="UTF-8"?>
<enabler>
  <name>my landing gear</name>
  <type> techno design</type>
  <subtype>landing gear</subtype>
  <timehorizon>
    <year>2030</year>
    <trl>5</trl>
    <ttm>P24M</ttm>
    <IM>
      <IMname>EpndB</IMname>
      <IMtype type="Metric">
        <Munit>dB</Munit>
        <Mvalue>4.5</Mvalue>
      </IMtype>
    </IM>
    <IM>
      <IMname>Nox</IMname>
      <IMtype type="Metric">
        <Munit>ppm</Munit>
        <Mvalue>4.5</Mvalue>
       </IMtype>
    </IM>
    <IM>
      <IMname>QOL</IMname>
      <IMtype type="Indicator">
      <Idescriptor>ppm</Idescriptor>
      <Ivalue>A+</Ivalue>
        </IMtype>
    </IM>
  </timehorizon>
  <timehorizon>
    <year>2050</year>
    <trl>7</trl>
    <ttm>P12M</ttm>
  </timehorizon>
 </enabler>

My own XSD file

<?xml version="1.0" encoding="utf-8"?>
<pps:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:pps="http://www.w3.org/2001/XMLSchema" xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning" vc:minVersion="1.1">
    <pps:element name="enabler">
        <pps:complexType>
            <pps:sequence>
                <pps:element name="name" type="pps:string" />
                <pps:element name="type" type="pps:string" />
                <pps:element name="subtype" type="pps:string" />
                <!-- Defining properties for each time horizon -->
                <pps:element name="timehorizon" minOccurs="1" maxOccurs="unbounded">
                    <pps:complexType>
                        <pps:sequence>
                            <pps:element name="year" type="pps:gYear"/>
                            <pps:element name="trl">
                                <pps:simpleType>
                                    <pps:restriction base="pps:integer">
                                        <pps:minInclusive value="1"/>
                                        <pps:maxInclusive value="12"/>
                                    </pps:restriction>
                                </pps:simpleType>
                            </pps:element> 
                            <pps:element name="ttm" type="pps:duration"/>
                            <!-- Defining Indicator or metric for each time horizon -->
                            <pps:element name="IM" minOccurs="0" maxOccurs="unbounded">
                                <pps:complexType>
                                    <pps:sequence>
                                        <pps:element name="IMname" type="pps:string"/>
                                        <pps:element name="IMtype" maxOccurs="unbounded">
                                          <pps:complexType>
                                            <pps:alternative test="@type = Metric" type="MetricType"/>
                                            <pps:alternative test="@type = Indicator" type="IndicatorType"/>
                                          </pps:complexType>
                                         </pps:element> 
                                  </pps:sequence>
                              </pps:complexType>
                          </pps:element>

                            <pps:complexType name="MetricType">
                                <pps:sequence>
                                    <pps:element name="Munit" type="pps:string"/>
                                    <pps:element name="Mvalue" type="pps:decimal"/>
                                </pps:sequence>
                            </pps:complexType>

                            <pps:complexType name="IndicatorType">
                                <pps:sequence>
                                    <pps:element name="Idescriptor" type="pps:string"/>
                                    <pps:element name="Ivalue" type="pps:string"/>
                                </pps:sequence>
                            </pps:complexType>
                                        
                        </pps:sequence>
                    </pps:complexType>
                </pps:element>
            </pps:sequence>
        </pps:complexType>
    </pps:element>
</pps:schema>
  • 1. You did not follow the linked example as your `alternative` elements do not have an `element` parent. 2. Declaring that your XSD uses version 1.1 is insufficient. Your XSD processor must actually support XSD 1.1. – kjhughes Mar 14 '23 at 12:00
  • thanks @kjhughes. I will try to find out the correct XSD 1.1. compliant syntax with xs:alternative (adding `element` parent seems not better) and above all what is a XSD processor. I am currently checking the syntax with online tools and/or with RStudio. – Mnatsortats Mar 15 '23 at 16:28
  • If you do not know for certain whether your tools support XSD 1.1, try the sample that I provide in the answer to the duplicate Q/A. It'll work iff the tool supports XSD 1.1. Without proven XSD 1.1 support, there's no use attempting to repair your `xsd:alternative` placement errors. – kjhughes Mar 15 '23 at 16:39
  • Thanks for this suggestion. I tried and your example failed to pass the test with RStudio therefore suggesting that it does not embark an XSD1.1 validation scheme. – Mnatsortats Mar 17 '23 at 12:25
  • However, being lazy, I ask Chat GTP about the failure and the reply (in French) is instructive: L'erreur que vous obtenez est due à deux raisons principales : Le fichier XML ne spécifie pas l'espace de noms approprié pour le schéma XSD. Vous devez ajouter l'attribut xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" à la balise racine du fichier XML et l'attribut xsi:noNamespaceSchemaLocation="votre_schema.xsd" pour spécifier le chemin d'accès au schéma XSD. Dans votre cas, cela ressemblerait à ceci : – Mnatsortats Mar 17 '23 at 12:27
  • La définition du type IMtype dans le schéma XSD est incorrecte. Vous devez envelopper la définition de l'élément IMtype dans une balise complexType pour définir les deux alternatives MetricType et IndicatorType. Vous pouvez corriger cela en modifiant la définition de IMtype dans votre schéma XSD comme suit : – Mnatsortats Mar 17 '23 at 12:30

0 Answers0