C sharp - Hacer que esta secuencia de carpetas sean strings

 
Vista:
sin imagen de perfil

Hacer que esta secuencia de carpetas sean strings

Publicado por Paulo (4 intervenciones) el 19/05/2015 15:03:42
Muy buenas! tengo una cosa que me está dando mucho quebradero de cabeza, os comento:

Tengo un programilla 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:

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
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";
 
 
 
            XmlDiff xmldiff = new XmlDiff(XmlDiffOptions.IgnoreChildOrder |
                                             XmlDiffOptions.IgnoreNamespaces |
                                             XmlDiffOptions.IgnorePrefixes);
            bool bIdentical = xmldiff.Compare(xmlString2, xmlString1, false, writexml);
 
 
            writexml.Close();
 
            FileStream patchedFile = new FileStream(xmlString3, FileMode.Create, FileAccess.Write);
 
            XmlPatch xmlPatch = new XmlPatch();
 
 
            try
            {
              //  XmlTextReader diffgramReader = new XmlTextReader("C:\\sharecompare.xml");
               // xmlpatch.Patch(sourceDoc, diffgramReader);
                xmlPatch.Patch(new XmlTextReader(xmlString2), patchedFile, new XmlTextReader(xmlString4));
 
 
            }
            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:




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
public static void CompareXml()
        {
            DShare Obj=new DShare();
 
            XmlWriter writexml;
 
            StringWriter sw = new StringWriter();
 
 
 
 
            writexml = XmlWriter.Create(sw);
 
 
            string xmlString1 = Obj.Xml2;
            string xmlString2 = Obj.Xml1;
            string xmlString3 = Obj.Xmlfinal;
            string xmlString4 = sw.ToString();
 
 
            string str = sw.ToString();//
 
 
 
            XmlDiff xmldiff = new XmlDiff(XmlDiffOptions.IgnoreChildOrder |
                                             XmlDiffOptions.IgnoreNamespaces |
                                             XmlDiffOptions.IgnorePrefixes);
            bool bIdentical = xmldiff.Compare(xmlString2, xmlString1, false, writexml);
 
 
            writexml.Close();
 
            MemoryStream ms = new MemoryStream(System.Text.Encoding.ASCII.GetBytes(xmlString3));
            //FileStream patchedFile = new FileStream(xmlString3, FileMode.Create, FileAccess.Write);
 
            XmlPatch xmlPatch = new XmlPatch();
 
 
            try
            {
                //  XmlTextReader diffgramReader = new XmlTextReader("C:\\sharecompare.xml");
                // xmlpatch.Patch(sourceDoc, diffgramReader);
                xmlPatch.Patch(new XmlTextReader(xmlString2), ms, new XmlTextReader(xmlString4));
 
 
            }
            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);
        }
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder