NathanaëlBeau
NathanaëlBeau

Reputation: 1152

XML validation : prefix expected without necessity?

I'm trying to validate my the following XML document :

<?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 testplugin.xsd" xmlns:tech="http://www.moss.fr/2011/moteur-xrm" xmlns:SCCOAMCD="urn:SCCOA-schemaInfo" xmlns:attribut="http://www.moss.fr/2012/attribut" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:mcd="urn:SCCOA-schemaInfo" xmlns:xrm="http://www.moss.fr/2011/connecteur_xrm" xmlns:variable="http://www.moss.fr/2012/variable" xmlns:doc="http://www.moss.fr/2011/documentation" xmlns:mtf2xsd="http://www.moss.fr/2010/mtf2xsd" xmlns:conv="http://www.moss.fr2010/conversion" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:SBEGestionZonesAeriennesSYSCA="urn:SBEGestionZonesAeriennesSYSCA-schema" xmlns:info="http://www.moss.fr/2011/information" xmlns="urn:SBEGestionZonesAeriennesSYSCA-schema">
<xrm:mapping occurs="xrm:mapping">
  <SBEGestionZonesAeriennesSYSCA xmlns=""
                                 info:obligatoire="true"
                                 occurs="/grappe"
                                 info:contexte="/grappe">
  </SBEGestionZonesAeriennesSYSCA>
 </xrm:mapping>
</xrm:plugin>

I'm using this main schema testplugin.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:nr0="http://NamespaceTest.com/balisesXrm" xmlns:SCCOAMCD="urn:SCCOA-schemaInfo" xmlns:metier="urn:SBEGestionZonesAeriennesSYSCA-schema"  targetNamespace="http://www.moss.fr/2011/connecteur_xrm" elementFormDefault="qualified" attributeFormDefault="unqualified" >
 <xsd:import namespace="http://NamespaceTest.com/balisesXrm"  schemaLocation="balisesXrm.xsd" />
 <xsd:import namespace="urn:SBEGestionZonesAeriennesSYSCA-schema" schemaLocation="metier1.xsd"/>

<xsd:complexType name="mapping">
      <xsd:sequence>
         <xsd:element ref="metier:SBEGestionZonesAeriennesSYSCA"/>
      </xsd:sequence>
</xsd:complexType>

 <xsd:element name="plugin">
  <xsd:complexType>
     <xsd:sequence>
        <xsd:element name="mapping" type="xrm:mapping"/>
     </xsd:sequence>
  </xsd:complexType>

With the import metier1.xsd :

<?xml version="1.0" encoding="utf-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:nr0="http://NamespaceTest.com/balisesXrm" xmlns:xalan="http://xml.apache.org/xslt" xmlns:SCCOAMCD="urn:SCCOA-schemaInfo" xmlns="urn:SBEGestionZonesAeriennesSYSCA-schema" xmlns:SBEGestionZonesAeriennesSYSCA="urn:SBEGestionZonesAeriennesSYSCA-schema"  attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="urn:SBEGestionZonesAeriennesSYSCA-schema" version="3.2.1ec">

  <xsd:element name="SBEGestionZonesAeriennesSYSCA" type="SBEGestionZonesAeriennesSYSCA:type_SBEGestionZonesAeriennesSYSCA"/>


 <xsd:complexType name="type_SBEGestionZonesAeriennesSYSCA">

   <xsd:sequence>

     <xsd:element maxOccurs="unbounded" name="Entities" type="SBEGestionZonesAeriennesSYSCA:type_Data_SBEGestionZonesAeriennesSYSCA"/>

   </xsd:sequence>

  <xsd:attributeGroup ref="attributsXrm"/>
 </xsd:complexType>

<xsd:attributeGroup name="attributsXrm">
  <xsd:attribute name="group-by"/>
  <xsd:attribute name="id"/>
  <xsd:attribute name="occurs"/>
</xsd:attributeGroup>

</xsd:schema>

I have the following error when I try to validate my XML :

Invalid content was found starting with element 'SBEGestionZonesAeriennesSYSCA'. One of {"urn:SBEGestionZonesAeriennesSYSCA-schema":SBEGestionZonesAeriennesSYSCA} is expected.

I have tried to change in my XML document the xmlns="urn:SBEGestionZonesAeriennesSYSCA-schema" by xmlns:s="urn:SBEGestionZonesAeriennesSYSCA-schema" and add to SBEGestionZonesAeriennesSYSCA the prefix s: and it works. But I can't understand why i have to put a prefix in this situation. Actually i don't want to modify my XML document but rather my XSD if it is possible. Thanks a lot.

Upvotes: 0

Views: 36

Answers (1)

Aaron
Aaron

Reputation: 24802

You should remove the xmlns="" attribute on the SBEGestionZonesAeriennesSYSCA tag in your XML, it sets the tag in the empty namespace.

Without it, the xmlns specified on your xrm:plugin tag, the expected urn:SBEGestionZonesAeriennesSYSCA-schema, will correctly be taken into account for your SBEGestionZonesAeriennesSYSCA tag.

It seems like a bad idea to modify the XSD rather than the XML, but if you really need to then you will need to have your XSD define the SBEGestionZonesAeriennesSYSCA element in the empty namespace, which you could do by removing the targetNamespace="urn:SBEGestionZonesAeriennesSYSCA-schema" attribute on your metier1.xsd's root and updating the reference to your element in the testplugin.xsd.

Upvotes: 1

Related Questions