1

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;
}
1
  • what are you expecting and what do you get? Commented Jun 11, 2013 at 3:03

2 Answers 2

2

If you want to return an XML document, you will have to change the content-type:

  ...
  Response.ContentType = "text/xml"; 
  Response.Write(contacts);
Sign up to request clarification or add additional context in comments.

Comments

0

Try to use this instead:

Response.Write(contacts.ToString());

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.