tags:

views:

42

answers:

1

I am expecting an xml as output when execute the following

XElement Root = XElement.Load(@"d:\xmlfiles\Customers.xml");
XElement BringContact = Root.Element("Contact");
Response.Write(BringContact);

as

<Contact>
  <Company>Alfreds Futterkiste</Company>
  <City>Berlin</City>
</Contact>

But the Response.Write() displays values only as

Alfreds Futterkiste Berlin

What is the code change do i need?

+1  A: 

That is because the browser is interpreting it as markup. Use "view source" in your browser to see the actual output.

You can also explicitly tell the browser you are returning xml by setting the content type:

  Response.ContentType = "text/xml";
  Response.ContentEncoding = Encoding.UTF8;
duckworth