Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从XML文档中删除空行_C#_Asp.net_Xml Parsing - Fatal编程技术网

C# 从XML文档中删除空行

C# 从XML文档中删除空行,c#,asp.net,xml-parsing,C#,Asp.net,Xml Parsing,我现在面临一个问题。我正在用C加载一个xml文件,从中删除一些节点并附加一些节点。现在的问题是,当我从xml文件中删除时,会自动创建一些空行,所以我想删除这些行 当我在xml中将一些节点附加到父节点时,我希望在每个结束标记中都有新行 例如,我的Xml文件是 <intro id="S0001"> <title>Introduction Title</title> <para>This is a paragraph. Note tha

我现在面临一个问题。我正在用C加载一个xml文件,从中删除一些节点并附加一些节点。现在的问题是,当我从xml文件中删除时,会自动创建一些空行,所以我想删除这些行

当我在xml中将一些节点附加到父节点时,我希望在每个结束标记中都有新行

例如,我的Xml文件是

<intro id="S0001">
    <title>Introduction Title</title>
     <para>This is a paragraph. Note that paragraphs can contain other block–level objects, such as lists, as well as directly containing text.</para>
     <para>The introduction can contain all of the text objects that a section can contain, except that it cannot be divided into parts, sections and sub–sections.</para>
     <para>The introduction can contain tables:</para>

   </intro><part>
       <no>Part A</no> Article Structure <sup>&lpar;Part Title&rpar;</sup><section1 id="S0002">`enter code here`
     <no>Sect 1</no>
     <title>First Section in Part 1 <sup>&lpar;Section 1 Title&rpar;</sup></title>
     <shortsectionhead>Short Section Header</shortsectionhead>
     <para>This is a section in the first part of the article.</para>
   </section1><section1 id="S0003">
请帮帮我
提前感谢

如果您使用C加载并保存XMl文件,那么应该正确格式化XMl。格式化外观奇怪的XMl文件的简单方法就是使用一些C代码加载并保存它们

如果我正确理解了您的问题,那么您只是对XML文件的格式不满意

就像你想要一个:

</intro><part>
但是你得到了B:

</intro>
<part>
如果这是一个问题,那么,在我看来,你只是想要一个奇怪的东西。因为

代码不关心XML文件的格式和格式 b中的格式是正确的


如果出于什么原因想要更改它,那么必须解析XML文件,将其作为字符串打开,并手动检查关闭和打开的标记

您能为您迄今为止所尝试的内容发布代码吗?XmlNode partNnode=xmlDoc.SelectSingleNode//part;XmlNode introNode=xmlDoc.SelectSingleNode//intro;XmlDocumentFragment newNode=xmlDoc.CreateDocumentFragment;newNode.InnerXml=partNnode.OuterXml;introNode.ParentNode.InsertAfternewNode,introNode;partNnode.ParentNode.RemoveChildpartNnode;partNnode=xmlDoc.SelectSingleNode//part;nodeList=xmlDoc.SelectNodes//section1;节点列表{newNode=xmlDoc.CreateDocumentFragment;newNode.InnerXml=refrangeNode.OuterXml;partNnode.AppendChildnewNode;}中的foreach XmlNode refrangeNode
</intro>
<part>