Tengo un programilla en visual studio funcionando que coge datos de 2 bases de datos,las convierte en archivos en xml,las compara y por ultimo las sincroniza, funciona perfectamente pero ahora quisiera hacer lo mismo pero sin crear ningún archivo, que todo el proceso ocurra internamente en el programa, os paso el código que tengo del programa funcionando (del método que hace todo el proceso de xml), y el código del nuevo, el problema ahora mismo me salta a la hora de comparar los dos strings y no descarto que lo que viene luego tampoco vaya a funcionar:
PROGRAMA FUNCIONANDO:
Código
public static void CompareXml() { XmlWriter writexml; writexml = XmlWriter.Create("C:\\sharecompare.xml"); string xmlString1 = "C:\\share2Copy.xml"; string xmlString2 = "C:\\share1.xml"; string xmlString3 = "C:\\sharecomparefinal.xml"; string xmlString4 = "C:\\sharecompare.xml"; XmlDiffOptions.IgnoreNamespaces | XmlDiffOptions.IgnorePrefixes); bool bIdentical = xmldiff.Compare(xmlString2, xmlString1, false, writexml); writexml.Close(); try { // XmlTextReader diffgramReader = new XmlTextReader("C:\\sharecompare.xml"); // xmlpatch.Patch(sourceDoc, diffgramReader); } catch (Exception ex) { Console.WriteLine("HA habido un ERROR: "+ex.Message); } patchedFile.Close(); Console.WriteLine("The patched document or fragment has been saved to " + xmlString3); }
INTENTO CONVERTIRLO EN UN PROGRAMA QUE FUNCIONE SIN CREAR ARCHIVOS. xml1 y xml2 son strings y cogen bien el xml de las bases de datos,el problema viene a la hora de intentar comparar los dos strings y sacar un tercer string con el resultado en formato xml:
Código
public static void CompareXml() { XmlWriter writexml; writexml = XmlWriter.Create(sw); string xmlString1 = Obj.Xml2; string xmlString2 = Obj.Xml1; string xmlString3 = Obj.Xmlfinal; string xmlString4 = sw.ToString(); string str = sw.ToString();// XmlDiffOptions.IgnoreNamespaces | XmlDiffOptions.IgnorePrefixes); bool bIdentical = xmldiff.Compare(xmlString2, xmlString1, false, writexml); writexml.Close(); //FileStream patchedFile = new FileStream(xmlString3, FileMode.Create, FileAccess.Write); try { // XmlTextReader diffgramReader = new XmlTextReader("C:\\sharecompare.xml"); // xmlpatch.Patch(sourceDoc, diffgramReader); } catch (Exception ex) { Console.WriteLine("HA habido un ERROR: " + ex.Message); } ms.Close(); // patchedFile.Close(); Console.WriteLine("The patched document or fragment has been saved to " + xmlString3); }