I have this code in my ASP.NET code-behind file:
Response.Write("<someting>")
But it doesn’t work. If I remove the < tag delimiter, then it writes the content to the page.
My question is: how can I write an XML string to the page from a code-behind?
What you’re doing is already fine. Your
<someting>tag isn’t showing on the page because the browser is expecting HTML, so it interprets<someting>as an HTML tag it doesn’t understand and displays nothing. If you look at the source of the page you should see the tag.Your XMLHttpRequest (XHR) request should be able to read this data as XML without a problem, even though it’s not displayed directly in the browser. However, as outlined in another answer, you should ideally change the content-type to
text/xml, so the client knows what data format to expect.