Hi I have below xml file that I am trying to load in xml document using below code -
XmlDocument Doc = new XmlDocument();
Doc.LoadXml(@\"C:\\MappingFiles\\Input
If you really want to read it in as a string and don't want to do XMLDocument.Load()
as others have suggested, you can do XMLDocument.LoadXml()
, but it should be as a string, first:
string myFilePath = @"C:\MappingFiles\InputFile.xml";
string allText = File.ReadAllText(myFilePath);
XmlDocument xmlDoc = new XmlDocument();
try
{
xmlDoc.LoadXml(allText);
}
catch (Exception ex)
{
Console.WriteLine("Error: " + ex.Message);
}
I found that this can work even when .Load()
on the file, itself, does not.