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?

2 Answers 2

1

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;
Sign up to request clarification or add additional context in comments.

Comments

0

You can use HttpUtility.HtmlEncode() to get the < > brackets to appear in the browser.

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.