当我尝试使用 XDocument 解析以下数据时,出现以下错误:
“XMLException:内部标记中不允许参数实体引用”
这是我试图解析的示例数据:
<!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>
这是尝试解析上述文件的代码:
string caFile = @"pathToFile";
using (var caStream = File.Open(caFile, FileMode.Open, FileAccess.Read))
{
var caDoc = XDocument.Load(caStream); // Exception thrown here!
}
有没有办法让内置的 .NET xml 解析库来处理实体引用,或者至少忽略嵌入的 !Doctype 并解析根元素?
注意:我假设参数实体引用在 XML 中有效。(见这里)