user603007
user603007

Reputation: 11794

xml display in asp.net page

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:

enter image description here

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

Answers (2)

fcuesta
fcuesta

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

roybalderama
roybalderama

Reputation: 1640

Try to use this instead:

Response.Write(contacts.ToString());

Upvotes: 0

Related Questions