Search code examples
xmlxsdxsd-validationxml-validation

XML schema : 'ref' or 'name' must be present in a local element declaration


I'm making an XML schema but the following error happens for all my elements :

One of 'ref' or 'name' must be present in a local element declaration.

I don't understand because I have a name or ref present in my XSD document as you can see here :

<?xml version="1.0" encoding="utf-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SCCOAMCD="urn:SCCOA-schemaInfo">
<xsd:import namespace="http://NamespaceTest.com/balisesXrm" schemaLocation="balisesXrm.xsd"/>
<xsd:import namespace="http://www.moss.fr/2011/connecteur_xrm"/>

<xsd:complexType xmlns="urn:SBEGestionZonesAeriennesSYSCA-schema" xmlns:SBEGestionZonesAeriennesSYSCA="urn:SBEGestionZonesAeriennesSYSCA-schema" name="typeAssociation">
    <xsd:sequence>
        <xsd:element xmlns:ns0="http://NamespaceTest.com/balisesXrm" ns0:ref="balisesXrmType"/>
  </xsd:sequence>
</xsd:complexType>

<xsd:element name="plugin">
  <xsd:complexType>
     <xsd:sequence>
        <xsd:element xmlns:ns0="http://www.moss.fr/2011/connecteur_xrm" ns0:name="xrm:header" type="header"/>
     </xsd:sequence>
  </xsd:complexType>
</xsd:element>

You can find here my balisesXrm.xsd document :

<?xml version="1.0" encoding="UTF-8"?>


<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
       targetNamespace="http://NamespaceTest.com/balisesXrm"
       xmlns:b="http://NamespaceTest.com/balisesXrm">


<xsd:complexType name="balisesXrm">
    <xsd:choice>
        <xsd:sequence>
            <xsd:element name="attribut" />
            <xsd:element name="variable" />
            <xsd:element name="param" />
            <xsd:element name="java" />
            <xsd:element name="historisation-date" />
        </xsd:sequence>
    </xsd:choice>
</xsd:complexType>


Solution

  • There error is telling you exactly the problem:

    One of 'ref' or 'name' must be present in a local element declaration.

    So for

      <xsd:element xmlns:ns0="http://NamespaceTest.com/balisesXrm" 
                   ns0:ref="balisesXrmType"/>
    

    remove the ns0 from @ns0:ref

      <xsd:element ref="balisesXrmType"/>
    

    and now you will have a @ref attribute as the error indicates you were missing. You've not provided a full MCVE, but this looks likely to be off. Typically a referenced element wouldn't have a Type suffix, so perhaps you instead mean,

      <xsd:element ref="balisesXrm"/>
    

    note that to reference balisesXrm in another namespace, declare a namespace prefix for that namespace, xmlns:ns0="http://NamespaceTest.com/balisesXrm", locally or better, at the root level as you'll likely need it elsewhere, and then use it on the @ref attribute value, not the name:

      <xsd:element ref="ns0:balisesXrm"/>
    

    or

      <xsd:element name="balisesXrm" type="ns0:balisesXrmType"/>
    

    There are too many other problems with your XSD to address in a single question, but this answer will at least allow you to progress past your current problem.