I was going to publish this, and that's when the servers went down. I think I correctly rewrote it from memory:
I think the problem is that by default it XPathDocumentuses XmlTextReaderto analyze the contents of the supplied file, and this one XmlTextReaderuses the parameter EntityHandling ExpandEntities.
In other words, when you rely on the default settings, it XmlTextReaderchecks the input XML and tries to resolve all entities. This is best done manually, with full control XmlReaderSettings(I always do it manually):
string myXMLFile = "SomeFile.xml";
string fileContent = LoadXML(myXMLFile);
private string LoadXML(string xml)
{
XPathDocument xDoc;
XmlReaderSettings xrs = new XmlReaderSettings();
xrs.CheckCharacters = false;
using (XmlReader xr = XmlReader.Create(xml, xrs))
{
xDoc = new XPathDocument(xr);
}
if (xDoc != null)
{
XPathNavigator xNav = xDoc.CreateNavigator();
return xNav.OuterXml;
}
else
return null;
}
source
share