I am trying to read an XML document without an entity extension, do some manipulations with it, and re-save it with unexpanded objects since they were originally.
When using XDocument directly, it does not load, throwing an exception, tell me that it has unexpanded objects:
XDocument doc = XDocument.Load(file); // <--- Exception // ... do some manipulation to doc doc.Save(file2);
Exception: reference to undeclared entity 'entityname'.
Then I tried to pass the XmlTextReader constructor to the XDocument constructor, but the EntityHandling property has no "no expand" extension:
XmlTextReader xmlReader = new XmlTextReader(file)); xmlReader.EntityHandling = EntityHandling.ExpandCharEntities; XDocument doc = XDocument.Load(xmlReader);
In addition, I looked at the XmlReader.Create function, but MSDN says: "Readers created with the Create method extend all entities."
How can I create an XmlReader that does not extend entities, or does not have an XDocument with entities?
decasteljau
source share