Search code examples
xmlxsdxml-namespacesxsd-validationxml-validation

How to declare element


I'm looking for validate an XML document with xrm prefix as you can read here :

I wrote the following XML Schema :

     </xsd:extension>

  </xsd:complexContent>

</xsd:complexType>


</xsd:schema>

However, when I check my XML document, I get the following error:

'xrm:plugin' is not a valid value for 'NCName'

I understand I can't put xrm: in my name, but how can I validate my xrm:plugin and xrm:header ? Because, if I try to validate my XML document, I get this error:

Cannot find the declaration of element 'xrm:plugin'.


Solution

  • xrm is a namespace prefix, an abbreviation for the namespace. As the syntax error indicates, a namespace prefix is not declared via xsd:element/@name. Instead, declare only the local name (plugin) and handle the namespace prefix declaration at the XSD level...

    Here is a simplified set of your XML and XSD where the XML validates successfully against the XSD:

    XML

    <?xml version="1.0" encoding="UTF-8"?>
    <xrm:plugin xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xsi:schemaLocation="http://www.moss.fr/2011/connecteur_xrm result.xsd"
                xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                xmlns:xrm="http://www.moss.fr/2011/connecteur_xrm">
      <xrm:header>
        <xrm:tracabilite>
          <xrm:reference_moss>MPD_4.1.1.0</xrm:reference_moss>
          <xrm:document_lie> </xrm:document_lie>
          <xrm:document_interface>SC-DIF-OT3402-0002-MOSS 1.8 - DIF COSCA Inc.2.doc</xrm:document_interface>
          <xrm:intervention>
            <xrm:auteur>Générateur de mapping v1.0</xrm:auteur>
            <xrm:date>14/01/2013</xrm:date>
            <xrm:commentaire>Génération du fichier de mapping</xrm:commentaire>
          </xrm:intervention>
        </xrm:tracabilite>
      </xrm:header>
    </xrm:plugin>
    

    XSD

    <?xml version="1.0" encoding="utf-8"?>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                xmlns:xrm="http://www.moss.fr/2011/connecteur_xrm"
                xmlns:SCCOAMCD="urn:SCCOA-schemaInfo"
                xmlns:SBEGestionZonesAeriennesSYSCA="urn:SBEGestionZonesAeriennesSYSCA-schema"
                SCCOAMCD:desc="  implémentation du MCD pivot du SCCOA 3.2.1ec  production par SCCOA mcd2mpd 4.1.1, le 11/12/2007  règles spécifiques production schémas 1.2  diagramme : A-SC.SBE GestionZonesAeriennes SYSCA  entité racine      : A-SC.ZoneAerienne "
                attributeFormDefault="unqualified"
                elementFormDefault="qualified"
                targetNamespace="http://www.moss.fr/2011/connecteur_xrm"
                version="3.2.1ec">
      <xsd:complexType name="header">
        <xsd:sequence>
          <xsd:any minOccurs="1" processContents="lax"/>
        </xsd:sequence>
      </xsd:complexType>
      <xsd:element name="plugin">
        <xsd:complexType>
          <xsd:sequence>
            <xsd:element name="header" type="xrm:header"/>
          </xsd:sequence>
        </xsd:complexType>
      </xsd:element>
    </xsd:schema>