c# Rookie Help regarding :: Parsing XML Error

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Daveg

    c# Rookie Help regarding :: Parsing XML Error

    Hello, Rookie here. I am new at c# and put together a
    script which is working fine grabbing some elements from
    an XML file that I created. The problem is that I would
    like to put at the top of the xml file some comments which
    document time, date, etc. If I open the file with the
    comments in a web browser it displays fine, but if I use
    the GetElementsByTa gName ("Some Element"); I get an error
    as if the method does not ignore the comments, it tries to
    parse them as well. Am I missing something?? For now I
    have removed any comments but would like to have them
    included.

    Problem Code commented out:

    //w.WriteLine("<!-- File: parse.cs -->");
    //w.WriteLine("Fi le: parse.cs");
    //w.WriteLine("Ti me: " + str);
    //w.WriteLine("-->");

    XmlNodeList nodes = doc.GetElements ByTagName ("Patch");
    foreach (XmlNode node in nodes)
    {
    string patchnames = node
    ["Name"].InnerText;

    string subvalue = node
    ["Key"].InnerText;
    //Console.WriteLi ne
    ("Subvalue " + subvalue + computername);

    string keyvalue = node
    ["Value"].InnerText;
    //Console.WriteLi ne
    ("keyvalue " + keyvalue + computername);

    string priority = node
    ["Priority"].InnerText;
    //Console.WriteLi ne
    ("keyvalue " + keyvalue + computername);
    }
    end of code snipet

    Thanks in advance
  • Daniel Bass

    #2
    Re: c# Rookie Help regarding :: Parsing XML Error

    //w.WriteLine("<!-- File: parse.cs -->");

    should be

    //w.WriteLine("<!-- File: parse.cs");

    you close your comment three lines later.



    "Daveg" <Dave@Guenthner s.com> wrote in message
    news:0a4a01c37e be$1034d610$a00 1280a@phx.gbl.. .
    Hello, Rookie here. I am new at c# and put together a
    script which is working fine grabbing some elements from
    an XML file that I created. The problem is that I would
    like to put at the top of the xml file some comments which
    document time, date, etc. If I open the file with the
    comments in a web browser it displays fine, but if I use
    the GetElementsByTa gName ("Some Element"); I get an error
    as if the method does not ignore the comments, it tries to
    parse them as well. Am I missing something?? For now I
    have removed any comments but would like to have them
    included.

    Problem Code commented out:

    //w.WriteLine("<!-- File: parse.cs -->");
    //w.WriteLine("Fi le: parse.cs");
    //w.WriteLine("Ti me: " + str);
    //w.WriteLine("-->");

    XmlNodeList nodes = doc.GetElements ByTagName ("Patch");
    foreach (XmlNode node in nodes)
    {
    string patchnames = node
    ["Name"].InnerText;

    string subvalue = node
    ["Key"].InnerText;
    //Console.WriteLi ne
    ("Subvalue " + subvalue + computername);

    string keyvalue = node
    ["Value"].InnerText;
    //Console.WriteLi ne
    ("keyvalue " + keyvalue + computername);

    string priority = node
    ["Priority"].InnerText;
    //Console.WriteLi ne
    ("keyvalue " + keyvalue + computername);
    }
    end of code snipet

    Thanks in advance


    Comment

    • Dave Guenthner

      #3
      Re: c# Rookie Help regarding :: Parsing XML Error

      Well, I changed code and still getting error. Updated
      code:

      w.WriteLine("<!-- File: parse.cs");
      w.WriteLine("Fi le: parse.cs");
      w.WriteLine("Ti me: " + str);
      w.WriteLine("Au th: Dave Guenthner");
      w.WriteLine("-->");
      w.WriteLine("<? xml version=\"1.0\" ?>");

      Error is : System.XML.xmlE xception

      Hmmmm....

      Comment

      Working...