C#中的LINQ to XML - 移除]; []"从DTD头人物 [英] C# LINQ TO XML - Remove "[]" characters from the DTD header

查看:146
本文介绍了C#中的LINQ to XML - 移除]; []"从DTD头人物的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近建立了一个小的C#Windows窗体/ LINQ到XML的应用程序在VS2010这不正是它应该做的,除了一件事:它增加了[]的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文档,一个空的内部子集自动插入如果它不存在的。 (内部子集是 [] 在包围的部分的&LT;!DOCTYPE&GT; )。

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。但是,如果你的旧系统不能处理它,你可以通过设置<一请从DTD内部子集href=\"http://msdn.microsoft.com/en-us/library/system.xml.linq.xdocumenttype.internalsubset\"><$c$c>XDocumentType.InternalSubset属性

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 - 移除]; []&QUOT;从DTD头人物的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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