0

Need to some help here. Trying to input an XML into a form in Visual Studio and have it display with the XML formatting in tact. I have gotten it to display as one long line but need the formatting to be there. I am using a label in the form to show the text, not sure if that is the best way or not but only way I could get it to work

This is in the Form1.cs

string FormatXML(string xml)
{
  XDocument.Load("Employee Roster.xml");
  XDocument doc = XDocument.Parse(xml);
  return(this.label1.Text = doc.ToString());
}

I have also tried

string FormatXML(string xml)
{
 XDocument.Load("Employee Roster.xml");

 try
 {
   XDocument doc = XDocument.Parse(xml);
   return(this.label1.Text = doc.ToString());
 }
 Catch
 {
   return xml
 }

I know there are other threads on this but they dont seem to specify how to define what file you are asking the form to read(I.E. the Load method)

buckeyebmr
  • 13
  • 4
  • 1
    This answer looks like it may be what you need: http://stackoverflow.com/questions/203528/what-is-the-simplest-way-to-get-indented-xml-with-line-breaks-from-xmldocument – Clay Ver Valen Oct 22 '15 at 16:29
  • You probably want to put it in a text box not a label. – Brian Oct 22 '15 at 16:33
  • You don't want to have this label in there at all! What does a label have to do with parsing XML? `doc.ToString()` returns formatted XML. – Gert Arnold Oct 25 '15 at 18:18

0 Answers0