When I try and parse the data below with XDocument I am getting the following error:
"XMLException: A parameter entity reference is not allowed in internal markup"
Here is an example data that I am trying to parse:
<!DOCTYPE sgml [
<!ELEMENT sgml ANY>
<!ENTITY % std "standard SGML">
<!ENTITY % signature " — &author;.">
<!ENTITY % question "Why couldn’t I publish my books directly in %std;?">
<!ENTITY % author "William Shakespeare">
]>
<sgml>&question;&signature;</sgml>
Here is the code that is trying to parse the file above:
string caFile = @"pathToFile";
using (var caStream = File.Open(caFile, FileMode.Open, FileAccess.Read))
{
var caDoc = XDocument.Load(caStream); // Exception thrown here!
}
Is there a way to get the built-in .NET xml parsing libraries to handle entity references, or at the very least ignore the embedded !Doctype and parse the root element?
NOTE: I am working under the assumption that parameter entity references are valid inside XML. (see here)