首页 > 代码库 > 修复使用<code>XmlDocument</code>加载含有DOCTYPE的Xml时,加载后增加“[]”字符的错误

修复使用<code>XmlDocument</code>加载含有DOCTYPE的Xml时,加载后增加“[]”字符的错误

C# LINQ TO XML - Remove “[]” characters from the DTD header

http://stackoverflow.com/questions/12358061/c-sharp-linq-to-xml-remove-characters-from-the-dtd-header

        public static void FixDocumentType(this XmlDocument xml)        {            if (xml?.DocumentType == null)                return;            var name = xml.DocumentType.Name;            var publicId = xml.DocumentType.PublicId;            var systemId = xml.DocumentType.SystemId;            var parent = xml.DocumentType.ParentNode;            var documentTypeWithNullInternalSubset = xml.CreateDocumentType(name, publicId, systemId, null);            if (parent == null || xml.DocumentType == null)                return;            parent.ReplaceChild(documentTypeWithNullInternalSubset, xml.DocumentType);        }

  

修复使用<code>XmlDocument</code>加载含有DOCTYPE的Xml时,加载后增加“[]”字符的错误