Exemplo n.º 1
0
 static void Sample8Test()
 {
     using (var parser = new ChoXmlReader("sample8.xml").WithXPath("/root/data")
                         .WithField("id", xPath: "@name")
                         .WithField("text", xPath: "/value")
            )
     {
         using (var writer = new ChoJSONWriter("sample8.json")
                             .Configure(c => c.SupportMultipleContent = true)
                )
             writer.Write(new { Texts = parser.ToArray() });
     }
 }
Exemplo n.º 2
0
        static void MergeXml()
        {
            IDictionary <string, dynamic[]> lookup = null;

            using (var r2 = new ChoXmlReader("XMLFile2.xml")
                            .WithXPath("//Transaction")
                   )
            {
                lookup = r2.GroupBy(rec1 => (string)rec1.JID).ToDictionary(lu => lu.Key, lu => lu.ToArray());
            }

            dynamic[] nodes = null;
            using (var r1 = new ChoXmlReader("XMLFile1.xml")
                            .WithXPath("//Journals")
                   )
            {
                nodes = r1.ToArray();
            }

            foreach (var rec in nodes)
            {
                if (lookup.ContainsKey((string)rec.JournalID))
                {
                    rec.Add("Transactions", lookup[(string)rec.JournalID]);
                }
            }

            foreach (var rec in nodes)
            {
                Console.WriteLine(rec.Dump());
            }

            StringBuilder xml = new StringBuilder();

            using (var w = new ChoXmlWriter(xml)
                           .Configure(c => c.UseXmlArray = false)
                   )
            {
                w.Write(nodes);
            }

            Console.WriteLine(xml.ToString());
        }