Я получаю следующую ошибку: -
System.InvalidOperationException: Состояние
XmlReader должно быть интерактивным.
at
System.Xml.Linq.XContainer.ReadContentFrom(XmlReader
r, LoadOptions o) at
System.Xml.Linq.XDocument.Load(XmlReader
Reader, параметры LoadOptions )
в следующем коде. Может ли кто-нибудь указать мне, что я здесь делаю не так?
static XDocument GetContentAsXDocument(string xmlData)
{
XmlDocument xmlDocument = new XmlDocument();
if (!string.IsNullOrEmpty(xmlData))
{
xmlDocument.LoadXml(xmlData);
return xmlDocument.ToXDocument();
}
else
{
return new XDocument();
}
}
///
/// Converts XMLDocument to XDocument
///
///
///
public static XDocument ToXDocument( this XmlDocument xmlDocument )
{
using( var nodeReader = new XmlNodeReader( xmlDocument ) )
{
nodeReader.MoveToContent();
return XDocument.Load(
nodeReader,
(LoadOptions.PreserveWhitespace |
LoadOptions.SetBaseUri |
LoadOptions.SetLineInfo));
}
}
Подробнее здесь: https://stackoverflow.com/questions/602 ... ument-load