problem with xml

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
 
G

Guest

Hi Melanieab,
it could be something to do with the contents of your XML file. What is
the XML inside the Catalog2.xml file?

Thanks
Mark R Dawson
 

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