Reputation: 15
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?
Upvotes: 1
Views: 517
Reputation: 1396
You can use HttpUtility.HtmlEncode()
to get the < > brackets to appear in the browser.
Upvotes: 0
Reputation: 5067
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;
Upvotes: 1