I'm making some html with the code running on WinForm. I want to make the following HTML:
& lt; Html & gt; & Lt; Body & gt; & Lt; Div & gt; & Lt; P & gt; Foo & lt; / P & gt; & Lt; / Div & gt; & Lt; / Body & gt; & Lt; / Html & gt;
I have been using the System.Web.UI.HtmlTextWriter class to do this very well:
System.Web.UI.HtmlTextWriter htmlWriter = New System.Web.UI.HtmlTextWriter (); HtmlWriter.WriteFullBeginTag ("HTML"); HtmlWriter.WriteLine (); HtmlWriter.WriteFullBeginTag ("body"); HtmlWriter.WriteLine (); HtmlWriter.Indent ++; HtmlWriter.WriteFullBeginTag ("div"); HtmlWriter.WriteLine (); HtmlWriter.Indent ++; HtmlWriter.WriteFullBeginTag ("P"); HtmlWriter.Write ("foo"); HtmlWriter.WriteEndTag ("P"); HtmlWriter.Indent--; HtmlWriter.WriteLine (); HtmlWriter.WriteEndTag ("div"); HtmlWriter.Indent--; HtmlWriter.WriteLine (); HtmlWriter.WriteEndTag ("body"); HtmlWriter.WriteLine (); HtmlWriter.WriteEndTag ("HTML");
It works just fine, however, when I open the resulting html in the text editor, my indentation just looks very far for me, because it's using tabs Is there any way to force this class to use several spaces instead?
I'm not a System.Web.UI boy, but, it seems that you are the HtmlTextWriter constructor As the second argument, indentation can supply characters for use. Thus, to get 4 places instead of one tab:
System.Web.UI.HtmlTextWriter htmlWriter = New System.Web.UI.HtmlTextWriter (yourTextWriter, "");
Comments
Post a Comment