Reputation: 11794
I have created xml with XElement, but when I display this on an aspx page the format is not what I would like which is:
c# code:
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; }
Upvotes: 1
Views: 377
Reputation: 4520
If you want to return an XML document, you will have to change the content-type:
...
Response.ContentType = "text/xml";
Response.Write(contacts);
Upvotes: 2
Reputation: 1640
Try to use this instead:
Response.Write(contacts.ToString());
Upvotes: 0