C# 删除xml节点中的空白,而不是属性值
从下面的输入xml中,我应该得到如下所述的输出xml 输入XmlC# 删除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>
<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);