“Data at the Root Level is invalid” with LoadXml

前端 未结 3 1939
傲寒
傲寒 2021-01-24 09:32

I have a code snippet :

XmlDocument doc = new XmlDocument();
try
{
    doc.LoadXml(xmlPath);
}
catch (Exception ex)
{
    string exMessage = ex.Message; 
}


        
相关标签:
3条回答
  • 2021-01-24 09:53

    Use doc.Load(xmlPath). LoadXML is for loading an XML string.

    0 讨论(0)
  • 2021-01-24 09:59

    does xmlPath contains the whole xml or a path to a file that contains it? The LoadXml method expects the actual XML, not a path to a file. If you want to load the xml using a path, using the Load method.

    0 讨论(0)
  • 2021-01-24 10:00

    You're passing a file path to a parameter that should contain the XML itself.

    0 讨论(0)
提交回复
热议问题