Beispiel #1
0
 static void LoadTextTest()
 {
     foreach (var x in ChoXmlReader.LoadText(@"<books><book name=""xxx"" author=""Tom""><title>C++</title></book><book name=""yyyy""></book></books>"))
     {
         Console.WriteLine(x.ToStringEx());
     }
 }
Beispiel #2
0
        static void QuickDynamicTest()
        {
            ArrayList al = new ArrayList();

            al.Add(1);
            al.Add("abc");

            List <int> lint = new List <int>()
            {
                1, 2
            };

            Hashtable ht = new Hashtable();

            ht.Add(1, "abc");

            ChoSerializableDictionary <int, string> dict = new ChoSerializableDictionary <int, string>();

            dict.Add(1, "abc");

            List <ExpandoObject> objs = new List <ExpandoObject>();
            dynamic rec1 = new ExpandoObject();

            rec1.Id       = 1;
            rec1.Name     = "Mark";
            rec1.IsActive = true;
            rec1.Message  = new ChoCDATA("Test");
            rec1.Array    = al;
            rec1.Lint     = lint;
            //rec1.HT = ht;
            rec1.Dict = dict;
            objs.Add(rec1);

            dynamic rec2 = new ExpandoObject();

            rec2.Id       = 2;
            rec2.Name     = "Jason";
            rec2.IsActive = true;
            rec2.Message  = new ChoCDATA("Test");
            objs.Add(rec2);

            StringBuilder sb = new StringBuilder();

            using (var parser = new ChoXmlWriter(sb).WithXPath("Employees/Employee"))
            {
                parser.Write(objs);
            }
            Console.WriteLine(sb.ToString());

            var a      = ChoXmlReader.LoadText(sb.ToString()).ToArray();
            var config = new ChoXmlRecordConfiguration();

            //config.Configure(c => c.RootName = "Root");
            Console.WriteLine(ChoXmlWriter.ToText(a.First(), config));
        }
Beispiel #3
0
        public static void CustomNodeNameTest()
        {
            string xml1 = @"<Root>
  <Node1>
    <Id>1</Id>
    <FirstName>Tom</FirstName>
  </Node1>
  <Node2>
    <Id>2</Id>
    <FirstName>Mark</FirstName>
  </Node2>
</Root>";

            using (var r = ChoXmlReader.LoadText(xml1))
            {
                foreach (var rec in r)
                {
                    Console.WriteLine(rec.Dump());
                }
            }

            return;

            string csv = @"Id, First Name
1, Tom
2, Mark";

            StringBuilder xml = new StringBuilder();

            using (var r = ChoCSVReader.LoadText(csv)
                           .WithFirstLineHeader())
            {
                using (var w = new ChoXmlWriter(xml)
                               .ErrorMode(ChoErrorMode.ThrowAndStop)
                               .Setup(s => s.CustomeNodeNameOverride += (o, e) =>
                {
                    e.NodeName = $"Node{e.Index}";
                })
                       )
                {
                    w.Write(r);
                }
            }

            Console.WriteLine(xml.ToString());

            //using (var reader = new ChoCSVReader("C:\\Server Media\\test3.csv")
            //    .WithFirstLineHeader()
            //    .Configure(c => c.FileHeaderConfiguration.IgnoreColumnsWithEmptyHeader = true)
            //    )
            //{
            //    using (var writer = new ChoXmlWriter(sb)
            //        .Configure(c => c.RootName = "Records")
            //        .Configure(c => c.NodeName = "Record")
            //        .Configure(c => c.EmptyXmlNodeValueHandling = ChoEmptyXmlNodeValueHandling.Empty)
            //        .Configure(c => c.ErrorMode = ChoErrorMode.ThrowAndStop)
            //        )
            //    {
            //        writer.Write(reader.Select(r =>
            //        {
            //            r.RenameKey("Company Name", "CompanyName");
            //            return r;
            //        }));
            //    }
            //}
        }