1

I have a requirement to generate an HTML snapshot of an object - basically on my app you can click on the Clipboard button and generate either Text, BB Bode or HTML and it goes through the object and builds a string of text which is copied to the Clipboard. You can then paste this snippet on forums, blogs, websites (ie. a way of sharing).

What is the most efficient way of writing HTML output? In ASP.NET I would use HtmlTextWriter but I can't use the System.Web assembly in Silverlight. I could write the tags manually but I was hoping there was a better way.

Note: This is nothing to do with the current HTML page or displaying HTML in Silverlight or Silverlight in HTML. The requirements are valid ;)

1 Answer 1

1

The closest thing to HTmlTextWriter thats actually available in Silverlight is XmlWriter.

StringBuilder sb = new StringBuilder();
XmlWriter writer = new XmlWriter(sb);

// use writer to create html content.

string html = sb.ToString();

Not as slick as using HtmlTextWriter but better than using StringBuilder directly. Just watch out for those elements that need a closing tag such as <div></div>.

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

1 Comment

Thanks Anthony, I spent about an hour Googling that but guess I was looking for the wrong thing! That set me one the right track..

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.