2009-10-14 11 views
-1

Je suis en train d'utiliser l'interface IXMLDOMDocument2 (C++) pour valider un document Xml contre un certain schéma et je reçois l'erreur suivante:erreur de validation du schéma « en double nom <element>: name = « X » »

Duplicate named <element> : name = '{http://www.site.com/MySchema}envelope'. 

J'ai du mal à comprendre ce que cela signifie - y a-t-il un problème avec mon schéma, ou est-ce un problème avec le Xml? J'ai vérifié à la fois le schéma et le Xml et ils contiennent à peine deux fois le mot "enveloppe"!

Le Xml:

<id:envelope xmlns:id="http://www.site.com/MySchema" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xsi:schemaLocation="http://www.site.com/MySchema MySchema.xsd"> 
    <id/> 
    <!-- Load of unimportant elements --> 
</id:envelope> 

xsd:

<xsd:schema targetNamespace="http://www.site.com/MySchema" 
      xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
      xmlns="http://www.site.com/MySchema" elementFormDefault="unqualified"> 
    <xsd:element name="envelope" type="envelopeType"> 
     <!-- etc... --> 
    </xsd:element> 
    <xsd:complexType name="envelopeType"> 
     <!-- etc... --> 
    </xsd:complexType> 
    <!-- load of other types... --> 
</xsd:schema> 
+0

Qu'en est-il de cette étiquette solitaire? Cela n'appartient pas à MySchema? –

+0

J'ai supposé que c'était le cas, grâce à la balise targetNamespace. N'est-ce pas? J'ai omis un grand nombre d'éléments qui sont nommés de la même façon (par exemple "expéditeur", plutôt que "id: expéditeur") donc j'ai supposé que ce n'était pas le problème (mais je ne sais pas: -S) – Justin

Répondre

1

je me suis dit ceci grâce à un commentaire laissé à la fin de this page sur MSDN:

In MSXML4, schemaLocation and noNamespaceSchemaLocation were never used during validation: you should use a SchemaCache containing the schemas against which the document was validated. This was fine, because it allowed me to use 'local' versions of the schemas that were referenced in the XML document.

In MSXML6, this was changed: "Inline schemas and schemas referenced from an instance using xsi:SchemaLocation are now added to an XML instance-specific cache which wraps the user-supplied SchemaCache." Now, when i use the SchemaCache and add the 'local' version of the schemas that were referenced in the XML document, i get this error message: "Duplicate named : name = 'ROOT'".

It seems both xsi:schemaLocation and the SchemaCache are used during validation resulting in a conflict. Ik know i can use ResolveExternal=False so xsi:schemaLocation won't be used, but in that case xsd:import/xsd:include are not resolved either, so that's not an option.

J'ai trouvé Je peux supprimer l'attribut schemaLocation du fichier xml d'entrée, ou ne pas ajouter explicitement le document MySchema.xsd La mise à jour du cache de schéma et la validation aboutiront. En fin de compte, j'ai décidé de supprimer l'attribut schemaLocation car il préserve le comportement existant - le Xml est uniquement utilisé en interne et donc il n'y a aucun risque de casser les clients existants.