G
Guest
Hi,
I'm trying to get xml working, but even when I copy/paste a simple example
from online, I get the error
An unhandled exception of type 'System.Xml.XmlException' occurred in
system.xml.dll
Additional information: System error.
Here is the code I used:
string filename = @"C:\Catalog2.xml";
XmlDocument xml = new XmlDocument();
xml.Load(filename);
XmlNode root = xml.DocumentElement; <- Here's where problem begins
XmlElement childNode = xml.CreateElement("childNode");
XmlElement childNode2 = xml.CreateElement("SecondChildNode");
XmlText textNode = xml.CreateTextNode("hello");
textNode.Value = "hello, world";
root.AppendChild(childNode);
childNode.AppendChild(childNode2);
childNode2.SetAttribute("Name", "Value");
childNode2.AppendChild(textNode);
textNode.Value = "replacing hello world";
xml.Save(filename);
I'm sure it's something simple that I'm missing, but it's driving me crazy.
Thanks for any help!
Mel
I'm trying to get xml working, but even when I copy/paste a simple example
from online, I get the error
An unhandled exception of type 'System.Xml.XmlException' occurred in
system.xml.dll
Additional information: System error.
Here is the code I used:
string filename = @"C:\Catalog2.xml";
XmlDocument xml = new XmlDocument();
xml.Load(filename);
XmlNode root = xml.DocumentElement; <- Here's where problem begins
XmlElement childNode = xml.CreateElement("childNode");
XmlElement childNode2 = xml.CreateElement("SecondChildNode");
XmlText textNode = xml.CreateTextNode("hello");
textNode.Value = "hello, world";
root.AppendChild(childNode);
childNode.AppendChild(childNode2);
childNode2.SetAttribute("Name", "Value");
childNode2.AppendChild(textNode);
textNode.Value = "replacing hello world";
xml.Save(filename);
I'm sure it's something simple that I'm missing, but it's driving me crazy.
Thanks for any help!
Mel