Dave Burke : Freelance .NET Web Developer specializing in Online Communities

Multiline Textboxes make for happy XmlTextWriter results

This is not what I wanted to be spending the majority of my late-night coding session on tonight, but here we are: 

Tonight's lesson:  If you want to display the results of an XML file straight-up with indentations and format you are accustomed to simply and quickly, do NOT display it in a label control.  Send it instead to a multi-line Textbox.

I got sidetracked into updating an XPath test page I use in the course of coding, based on one of many good code examples in Wrox's Professional ASP.NET XML with C#.  I last wrote on this in a June post.

At bottom is the comparison between displaying the XML file in a textbox (at left in white) and a label (in pink).  I anticipate someone telling me I missed some label attribute or perhaps should have used encoding of some kind, which I would of course welcome.  Here's the code for a quick display of the XML file.

string _XmlDocPath =Server.MapPath(Request.ApplicationPath + "/xml/" + txtFilename.Text);
StringWriter sw = new StringWriter();
XmlTextWriter writer = new XmlTextWriter(sw);
writer.Formatting = Formatting.Indented;
writer.Indentation = 4;
XmlDocument doc = new XmlDocument();
doc.Load(_XmlDocPath);
doc.WriteTo(writer);
txtResults.Text = sw.ToString(); 
SubSelectLabel.Text = sw.ToString();


 

 

Comments (0) | Post RSS RSS comment feed

Posted on 9/23/2003 10:25:00 PM by Dave Burke
Categories:
Tags:

Related posts


Powered by BlogEngine.NET 2.0.0.36
Theme by Dave Burke