从xml响应中删除空格

问题描述 投票:-2回答:1

下面是创建xml的示例代码。

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.Value;

下面显示了当前输出xml,您可以看到字符和单词之间有空格:

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

而不是上面的xml,我希望如下修剪xml:

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

请同样帮助!

c# xml
1个回答
1
投票

下面是将解决问题的示例代码。

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);
© www.soinside.com 2019 - 2024. All rights reserved.