Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/305.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/25.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#_.net_Xml_Xml Parsing - Fatal编程技术网

C# 删除xml节点中的空白,而不是属性值

C# 删除xml节点中的空白,而不是属性值,c#,.net,xml,xml-parsing,C#,.net,Xml,Xml Parsing,从下面的输入xml中,我应该得到如下所述的输出xml 输入Xml <BPSResponse> <Response> <Code>804</Code> <Text>TagID value is not genuine.</Text> </Response> </BPSResponse> 输出Xml <BPSResponse><Response>

从下面的输入xml中,我应该得到如下所述的输出xml

输入Xml

<BPSResponse>    <Response>      <Code>804</Code>      <Text>TagID value is not genuine.</Text>    </Response>  </BPSResponse>
输出Xml

<BPSResponse><Response><Code>804</Code><Text>TagID value is not genuine.</Text></Response></BPSResponse>
我正在通过XElement创建xml

var bpsResponseXml = new XElement("BPSResponse");

            for (int i = 0; i < bpsResponseStatusCodes.Count; i++)
            {
                var bpsResponse = BPSResponseDictionary.GetBPSResponse(bpsResponseStatusCodes[i]);

                bpsResponseXml.Add(new XElement("Response",
                                    new XElement("Code", bpsResponse.Code),
                                    new XElement("Text", bpsResponse.Text)));
            }

            var outPutXml = bpsResponseXml.Value;
var bpsResponseXml=new-XElement(“BPSResponse”);
对于(int i=0;i

我希望输出如上格式的xml。

在转换为字符串时,我只需禁用格式。下面是示例代码

var doc = new System.Xml.XmlDocument()
{
    PreserveWhitespace = false
};
doc.LoadXml(xmlString);
string flat = doc.OuterXml;
var bpsResponseXml = new XElement("BPSResponse");         

bpsResponseXml.Add(new XElement("Response",
                                    new XElement("Code", "804"),
                                    new XElement("Text", "TagID value is not genuine")));

var outPutXml = bpsResponseXml.ToString(System.Xml.Linq.SaveOptions.DisableFormatting);