wpf2009. 8. 28. 11:16
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);


출처 : http://weblogs.asp.net/scottcate/archive/2006/11/13/Loading-an-XML-Document-from-a-File-or-a-String.aspx

Posted by 동동(이재동)