0

Is there an easy way to write an XElement object to a browser so that it's formatted nicely, like this: http://www.4guysfromrolla.com/demos/UserInfoWriter.2.aspx? I don't want to have to create any sort of strongly typed class, or explicitly write every node.

Example:

var xElement = new XElement("test", new XElement("node", "1"));

can I do something with xElement at this point?

3 Answers 3

1

Have you tried just using an XML server control and that doesnt meet your needs? It is specifically for the purpose of displaying XML on a web page.

Here is the link to MSDN

Sign up to request clarification or add additional context in comments.

Comments

0

It depends on what you're trying to do, but if you change content type to text/xml the browser will display formatted XML. However, this won't work if you have other content you're trying to display on the page.

1 Comment

This works. This is the only line in my aspx page: <%@ Page [...] ContentType="text/xml" %> And this in the code behind: Response.Write(xElement.ToString());
0

Well if you want to serialize that XElement object to the browser use e.g.

Response.ContentType = "application/xml";
xElement.Save(Response.OutputStream);

As others have noted, that is only useful if your ASP.NET page sends nothing but that XML document to 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.