Error saving list items in XML

Discussion in 'C#' started by shah123, May 18, 2007.

  1. shah123

    shah123 New Member

    Joined:
    Mar 27, 2007
    Messages:
    84
    Likes Received:
    0
    Trophy Points:
    0
    I am getting this error when i add xml code to my application. Basically I am trying to add listitems to XML file.

    Code:
    private const string filename = "C:\\schedulers.xml";            
    XmlTextWriter sch = null;
                sch = new XmlTextWriter(filename, null);
                sch.Formatting = Formatting.Indented;
                sch.Namespaces = false;
    try
                    {
                        sch.WriteStartDocument();
    
                        sch.WriteStartElement("", "Schedules", "");
    
                        sch.WriteStartElement("", "Scheduler", "");
                        sch.WriteString(subjTextbox.Text.ToString());
                        sch.WriteEndElement();
    
                        sch.WriteStartElement("", "FileName", "");
                        sch.WriteString(textFile.Text.ToString());
                        sch.WriteEndElement();
    
                        sch.WriteStartElement("", "Date & Time", "");
                        sch.WriteString(date.ToString());
                        sch.WriteEndElement();
    
                        sch.WriteEndElement();
                        sch.Flush();
                    }
                    catch (Exception e1)
                    {
                        MessageBox.Show(e1.Message);
    
                    }
    

    Error:

    Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.


    --------------------------------------------------------------------------------

    A name was started with an invalid character. Error processing resource 'file:///C:/schedulers.xml'. Line 5, Position 9

    <Date & Time>18/05/2007 02:02:00</Date & Time>
    --------^


    please help
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    probably the node should be without space or &
     
  3. shah123

    shah123 New Member

    Joined:
    Mar 27, 2007
    Messages:
    84
    Likes Received:
    0
    Trophy Points:
    0
    Yup It Worked .. Thanks
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice