1

XElement を使用して xml を作成しましたが、これを aspx ページに表示すると、希望する形式ではありません。

ここに画像の説明を入力

c# コード:

var persons = new[] {
    new Person {
        Name = "Patrick Hines",
        PhoneNumbers = new[] { "206-555-0144", "425-555-0145" }
    },
    new Person {
        Name = "Gretchen Rivas",
        PhoneNumbers = new[] { "206-555-0163" }
    }
};

XElement contacts = new XElement("contacts",
                        from p in persons
                        select new XElement("contact",
                             new XElement("name", p.Name),
                                 from ph in p.PhoneNumbers
                                 select new XElement("phone", ph)
                              ));

            Response.Write(contacts);
class Person
{
    public string Name;
    public string[] PhoneNumbers;
}
4

2 に答える 2