C# LINQ TO XML - 删除“[]";来自 DTD 标头的字符 [英] C# LINQ TO XML - Remove "[]" characters from the DTD header

查看:24
本文介绍了C# LINQ TO XML - 删除“[]";来自 DTD 标头的字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近在 VS2010 中创建了一个小的 C# windows 窗体/LINQ to XML 应用程序,它完全按照它应该做的事情做,除了一件事:它在 DOCTYPE 标签的末尾添加了[]",这显然导致要从旧系统中拒绝的文件.这是之前和之后:

I recently created a small C# windows forms/LINQ to XML app in VS2010 that does exactly what it's supposed to do, except for one thing: it adds "[]" to the end of the DOCTYPE tag, which apparently is causing files to be rejected from a legacy system. Here's a before and after:

之前

<!DOCTYPE ichicsr SYSTEM "http://www.accessdata.fda.gov/xml/icsr-xml-v2.1.dtd">

之后

<!DOCTYPE ichicsr SYSTEM "http://www.accessdata.fda.gov/xml/icsr-xml-v2.1.dtd"[]>

在使用 .Save 函数将文件保存在程序中后,这些字符会被添加.该程序允许选择一个 .xml 文件,然后通过删除某些标签来清理"它,然后保存它.当进程开始时,文件在 DOCTYPE 中没有[]".保存后,他们这样做.LINQ to XML 是否添加了这些?

These characters get added after the file is saved within the program using the .Save function. The program allows selection of an .xml file, then "cleans" it by removing certain tags, then saves it. When the process begins, the files do not have the "[]" in the DOCTYPE. After saving, they do. Does LINQ to XML add these?

有什么办法可以让程序不添加这些字符?

Is there any way to keep the program from adding these characters?

推荐答案

显然,当 XDocument 解析包含文档类型声明的 XML 文档时,会自动插入一个空的内部子集",如果不存在.(内部子集是[]包围的部分).

Evidently, when XDocument parses an XML document that contains a Document Type Declaration, an empty "internal subset" is automatically inserted if one doesn't exist. (The internal subset is the part surrounded by [] in the <!DOCTYPE>).

结果是格式良好的 XML.但是,如果您的旧系统无法处理它,您可以通过设置 XDocumentType.InternalSubset 属性为 null:

The result is well-formed XML. However, if your legacy system can't handle it, you can remove the internal subset from the DTD by setting the XDocumentType.InternalSubset property to null:

XDocument document = ...;
if (document.DocumentType != null)
    document.DocumentType.InternalSubset = null;

这篇关于C# LINQ TO XML - 删除“[]";来自 DTD 标头的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆