Scott Cate's WebLog

You just don't know what
you don't know.

community

frenz

my book(s)

my products

Loading an XML Document from a File or a String

I just got stuck on something, and it was one of those "in your face" type of solutions that my friend Jeff Julian had to help me with.

I have a file called c:\temp.xml.

In C# I was trying to load this into a XmlDocument. Easy enough.

XmlDocument xml = new XmlDocument();
xml.Load("c:\temp.xml");

Of course the values aren't hard coded, but for the point this works fine.

Here was my problem. I had the contents of c:\temp.xml already loaded in as a string called xmlContents. So I was trying to

xml.Load(xmlContents);

And I was getting an "Invalid URI" error.

The solution.

xml.LoadXml(xmlContents);

Worked perfectly. One of those little oversights that I could have spent hours on, where another set of eyes/ears helped in a few seconds.

Thanks Jeff.

Posted: Nov 13 2006, 09:34 AM by scott cate | with 4 comment(s)
Filed under:

Comments

Pat King said:

Hey thanks! Simple but brilliant.

# February 4, 2007 8:44 PM

rlong said:

And thanks for saving me an equivalent amount of time!
# June 12, 2007 3:03 PM

Aymane Bens said:

Thank's that helps a lot !!

# June 27, 2008 4:50 AM

Vidyadhar said:

thanks for saving my time

# December 12, 2008 7:04 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)