You are not showing your source code, but I assume you are doing this:
string xml = ... retrieve ...; XmlDocument doc = new XmlDocument(); doc.Load(xml);
The Load method assumes that the file name is not XML itself. To load the actual XML, simply use the LoadXml method:
... same code ... doc.LoadXml(xml);
Similarly, using XDocument , the Load(string) method expects a file name, not the actual XML. However, there is no LoadXml method, so the correct way to load XML from a string is as follows:
string xml = ... retrieve ...; XDocument doc; using (StringReader s = new StringReader(xml)) { doc = XDocument.Load(s); }
In fact, when developing something, it is a very good idea to pay attention to the semantics (value) of parameters of not only their types. If the type of the parameter is string , this does not mean that you can only feed anything that is a string.
Also regarding your updated question, it makes no sense to use XmlDocument and XDocument at the same time. Choose one or the other.
Ondrej Tucny Oct 30 2018-10-10T00: 00Z
source share