c# Rookie Help regarding :: Parsing XML Error

D

Daveg

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 GetElementsByTagName ("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("File: parse.cs");
//w.WriteLine("Time: " + str);
//w.WriteLine("-->");

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

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

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

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

Thanks in advance
 
D

Daniel Bass

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

should be

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

you close your comment three lines later.



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 GetElementsByTagName ("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("File: parse.cs");
//w.WriteLine("Time: " + str);
//w.WriteLine("-->");

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

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

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

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

Thanks in advance
 
D

Dave Guenthner

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

w.WriteLine("<!-- File: parse.cs");
w.WriteLine("File: parse.cs");
w.WriteLine("Time: " + str);
w.WriteLine("Auth: Dave Guenthner");
w.WriteLine("-->");
w.WriteLine("<?xml version=\"1.0\"?>");

Error is : System.XML.xmlException

Hmmmm....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top