str1 = doc1.OuterXml; str2 = doc2.OuterXml; if (str1.CompareTo(str2)==0) { //document identique ... } else { //pas identique, alors parcourir les document XML .... }
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question.... XmlDocument doc1 = new XmlDocument(); XmlDocument doc2 = new XmlDocument(); doc1.LoadXml("<Name>Rey</Name><FirstName>Jacques</FirstName>35 <Street>Rue de la Gare</Street><City np='3003'>Berne</City> "); doc2.LoadXml("<Name>Rey</Name><FirstName>Jacques</FirstName>40 <Rue>Rue de la Gare</Rue><City>Berne</City> "); string str1 = doc1.OuterXml; string str2 = doc2.OuterXml; if (str1.CompareTo(str2) == 0) { //document identique Console.WriteLine("Document identique"); } else { //pas identique, alors parcourir les document XML XmlNode root1 = doc1.DocumentElement; XmlNode root2 = doc2.DocumentElement; while ((root1 != null) && (root2 != null)) { if (root1.InnerXml != root2.InnerXml) { Console.WriteLine("Contenu des noeuds '" + root1.Name + "' différent"); } if (root1.Name != root2.Name) { Console.WriteLine("Nom de noeud différent: " + root1.Name+ " - "+ root2.Name); } if (root1.Attributes.Count != root2.Attributes.Count) { Console.WriteLine("Nombre d'attributs différents: "+root1.Name); } else { //Comparer le contenu de chaque attribut XmlAttributeCollection att1 = root1.Attributes; XmlAttributeCollection att2 = root2.Attributes; if ((att1 != null) && (att2 != null)) { int ind = 0; while (ind < att1.Count) { if (att1[ind].InnerXml != att2[ind].InnerXml) { Console.WriteLine("Le contenu des attributs:'" + att1[ind].Name + "' est différent"); } ind = ind + 1; } } } if (root1.FirstChild.NodeType == XmlNodeType.Element) { root1 = root1.FirstChild; } else { if (root1.NextSibling == null) { root1 = root1.ParentNode.NextSibling; } else { root1 = root1.NextSibling; } } if (root2.FirstChild.NodeType == XmlNodeType.Element) { root2 = root2.FirstChild; } else { if (root2.NextSibling == null) { root2 = root2.ParentNode.NextSibling; } else { root2 = root2.NextSibling; } } } } ....