Validation XML

nad008 Messages postés 10 Date d'inscription mardi 1 mars 2005 Statut Membre Dernière intervention 25 mars 2005 - 1 mars 2005 à 14:49
nad008 Messages postés 10 Date d'inscription mardi 1 mars 2005 Statut Membre Dernière intervention 25 mars 2005 - 7 mars 2005 à 11:37
Salut,

Je voudrais valider un fichier XML avec un schéma XSD, pour cela j'ai utilisé le code suivant :

Dim bReturn As Boolean
Dim schema As New MSXML2.XMLSchemaCache
Dim parseError As IXMLDOMParseError
Dim xmlSchema As New MSXML2.DOMDocument
Dim xmlToValidate As New MSXML2.DOMDocument
Dim bSchema As Boolean

bReturn = False
xmlSchema.async = False
bSchema = xmlSchema.Load(App.Path & "" & XSD_FILE)


If (bSchema) Then
schema.Add "xmlns:xs", xmlSchema
Set xmlToValidate.schemas = schema


xmlToValidate.validateOnParse = True
bReturn = xmlToValidate.Load(txtDocumentPath.text)


Set parseError = xmlToValidate.Validate
End If

J'obtiens alors une erreur "Incorrect definition for the root element in schema"

merci pour votre aide

2 réponses

nad008 Messages postés 10 Date d'inscription mardi 1 mars 2005 Statut Membre Dernière intervention 25 mars 2005
1 mars 2005 à 16:46
J'ai maintenant un autre souci toujours sur la validation de mon fichier XML par rapport au schéma.
J'ai modifié mon code comme suit :

Dim schema As New MSXML2.XMLSchemaCache40
Dim parseError As IXMLDOMParseError
Dim xmlSchema As New MSXML2.DOMDocument40
Dim xmlToValidate As New MSXML2.DOMDocument40

après avoir téléchager MSXML4 (SP2) sut le site de microsoft

Maintenant j'ai ce message d'erreur :
"l'espace nom xmlns:xs fourni est différent de l'espace de nom cible du schéma"

Est-ce qqn aurait une idée pour résoudre ça?

merci
0
nad008 Messages postés 10 Date d'inscription mardi 1 mars 2005 Statut Membre Dernière intervention 25 mars 2005
7 mars 2005 à 11:37
Réponse : en utilisant ce lien http://www.developerfusion.com/show/2386/2/
j'ai trouvé la réponse à ma question

le code est le suivant :
Private Sub Validation_Click()


Dim schemaCache As MSXML2.XMLSchemaCache40
Dim doc As MSXML2.DOMDocument40

Set schemaCache = New MSXML2.XMLSchemaCache40
schemaCache.Add "
http://www.govtalk.gov.uk/CM/envelope", App.Path & "\xsd" & ENVELOPE_XSD
schemaCache.Add "
http://www.govtalk.gov.uk/taxation/EOY", App.Path & "\xsd" & EOY_SCHEMA_XSD
Set doc = New MSXML2.DOMDocument40
Set doc.schemas = schemaCache
doc.async = False


If Not doc.Load(txtDocumentPath.text) Then
MsgBox "Error loading XML document: " & doc.parseError.reason
Else
MsgBox "Validation OK"
End If

End Sub
0
Rejoignez-nous