none
XML LINQ Document

    Question

  • I am trying to create a XML document with LINQ.  I am having a hard time lining up the jClass classes and XML LINQ.  I am trying to gwt to this form:

    <count><place><first>1</first><second>2</second><third>3</third></place><place><first>11</first>...</place><‌​/count>.

                var serializer = new JavaScriptSerializer();
                var json1 = "{[count:{first:1,second:2,third:3},{first:11,second:22,third:33},{first:111,second:222,third:333}]}";
                var jsons = serializer.Serialize(json1);
                var jsona = serializer.Deserialize<List<jClass>>(jsons);
                var xmld = new XDocument(
                    new XElement("count", jsona.Select(c =>
                        new XElement("place",
                            new XElement("first", c.first),
                            new XElement("second", c.second),
                            new XElement("third", c.third)
                        )
                    ))
                );

    public class jClass
        {
            public jTopThree[] count { get; set; }
        }
        public class jTopThree
        {
            public int first { get; set; }
            public int second { get; set; }
            public int third { get; set; }
        }

    Friday, March 31, 2017 9:05 AM

Answers