IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C# Discussion :

Comparer 2 fichiers xml


Sujet :

C#

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Candidat au Club
    Homme Profil pro
    Consultant MOA
    Inscrit en
    Avril 2014
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Consultant MOA

    Informations forums :
    Inscription : Avril 2014
    Messages : 2
    Par défaut Comparer 2 fichiers xml
    Bonjour,
    Je suis débutant en c#
    Je travail sur un outils d'automatisation de tests(Ranorex), et je voudrai comparer 2fichiers xml, qui ne sont pas identique.
    L'idée est de vérifier qu'on trouve bien les données du fichier source parmi les données du fichier en sorti.
    Le probleme est que mon code ne me remonte rien, pourtant qu'il y a pas d'erreurs. merci de m'aider
    Voici mon code:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Text.RegularExpressions;
    using System.Drawing;
    using System.Threading;
    using WinForms = System.Windows.Forms;
     
    using Ranorex;
    using Ranorex.Core;
    using Ranorex.Core.Testing;
    using System.IO;
    using System.Xml;
     
    namespace RECONCILIATION.Recording.AUTRE
    {
        public partial class ComparerFichierXlmInjecteFichierXmlReponse
        {
            /// <summary>
            /// This method gets called right after the recording has been started.
            /// It can be used to execute recording specific initialization code.
            /// </summary>
            private void Init()
            {
                // Your recording specific initialization code goes here.
            }
     
            public void CompareInputAndOutputFiles()
            {
    			string source = FileSourcePath;
    			string actual = FileActualPath;
     
    			if (MatchXML(source, actual))
    			{
    			   Console.WriteLine("Matches");
    			}
    			else
    			{
    			   Console.WriteLine("Does not match");
    			   Console.ReadLine();
    			}
            } 
     
    		static bool MatchXML(string FileSourcePath, string FileActualPath)
    		{				
    		string sourceClePCE, sourceIdExterneDemandeConso, sourceDateDebutDemandeConso, sourceDateFinDemandeConso, sourcePasDemandeConso;
    		string idExterneDemandeConso ="", dateDebutDemandeConso ="", dateFinDemandeConso ="", pasDemandeConso ="";
     
    			using (XmlReader xr = XmlReader.Create(FileSourcePath))
    			{
    			    // Get ClePCE
    			    xr.ReadToFollowing("clePCE");
    				sourceClePCE = xr.ReadString();
     
    				// Get IdExterneDemandeConso
    				xr.ReadToFollowing("idExterneDemandeConso");
    				sourceIdExterneDemandeConso = xr.ReadString();
     
    				// Get DateDebutDemandeConso
    				xr.ReadToFollowing("dateDebutDemandeConso");
    				sourceDateDebutDemandeConso = xr.ReadString();
     
    				// Get DateFinDemandeConso
    				xr.ReadToFollowing("dateFinDemandeConso");
    				sourceDateFinDemandeConso = xr.ReadString();
     
    				// Get PasDemandeConso
    				xr.ReadToFollowing("pasDemandeConso");
    				sourcePasDemandeConso = xr.ReadString();
     
    				Report.Log(ReportLevel.Info, sourceClePCE);
     
    			 }
     
    			using (XmlReader xr = XmlReader.Create(FileActualPath))
    			{				
    				while (!xr.EOF)
    				{
    				  xr.ReadToFollowing("clePCE");
    				}
     
    				if (xr.ReadString() == sourceClePCE)
    				{
    					// Get actual IdExterneDemandeConso
    					xr.ReadToFollowing("idExterneDemandeConso");
    					idExterneDemandeConso = xr.ReadString();
     
    					// Get actual DateDebutDemandeConso
    					xr.ReadToFollowing("dateDebutDemandeConso");
    					dateDebutDemandeConso = xr.ReadString();
     
    					// Get actual DateFinDemandeConso
    					xr.ReadToFollowing("dateFinDemandeConso");
    					dateFinDemandeConso = xr.ReadString();
     
    					// Get actual PasDemandeConso
    					xr.ReadToFollowing("pasDemandeConso");
    					pasDemandeConso = xr.ReadString();
     
    					Report.Log(ReportLevel.Info, sourceIdExterneDemandeConso);
    				}
     
    				if (sourceIdExterneDemandeConso == idExterneDemandeConso && sourceDateDebutDemandeConso == dateDebutDemandeConso && sourcePasDemandeConso == pasDemandeConso && sourceDateFinDemandeConso == dateFinDemandeConso)
    				{
    				  return true; // Matches
    				}
     
    				// Does not match
    				{
    				  return false;
    				}
     
          	 	 }
     
       		 }
    	}
    }

  2. #2
    Membre confirmé Avatar de Altor
    Homme Profil pro
    Développeur C#.NeT / Administrateur S.I. en alternance / Étudiant CS2I à Nevers
    Inscrit en
    Septembre 2012
    Messages
    103
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 32
    Localisation : France, Nièvre (Bourgogne)

    Informations professionnelles :
    Activité : Développeur C#.NeT / Administrateur S.I. en alternance / Étudiant CS2I à Nevers
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2012
    Messages : 103
    Par défaut
    J'ai pas trop compris ce que tu souhaite faire.

    Est-ce que tu voudrais vérifier si c'est exactement le même fichier, ou si les balises principales sont présentes ?

Discussions similaires

  1. [DOM] comparer 2 fichiers xml
    Par ben7875 dans le forum XML/XSL et SOAP
    Réponses: 12
    Dernier message: 26/06/2011, 14h32
  2. Comparer deux fichiers XML - un local et un externe
    Par gtraxx dans le forum Langage
    Réponses: 6
    Dernier message: 14/12/2009, 11h46
  3. outils pour comparer deux fichiers xml
    Par donny dans le forum XML/XSL et SOAP
    Réponses: 1
    Dernier message: 17/03/2008, 20h06
  4. Réponses: 1
    Dernier message: 10/09/2006, 16h09
  5. [JDOM] Comparer deux fichiers XML en Java
    Par calimero2611 dans le forum Format d'échange (XML, JSON...)
    Réponses: 5
    Dernier message: 30/06/2006, 11h19

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo