【问题标题】:How to remove white spaces in XML Document in C#如何在 C# 中删除 XML 文档中的空格
【发布时间】:2011-08-03 01:08:03
【问题描述】:

谁能帮我解决如何删除 XML 标记之间的所有空格,如下所示:

<?xml version="1.0"?>
<note>
    <to>Tove</to>
    <from>Jani</from>
    <heading>Reminder</heading>
    <body>Don't forget me this weekend!</body>
</note>

收件人:

<?xml version="1.0"?><note><to>Tove</to><from>Jani</from><heading>Reminder</heading><body>Don't forget me this weekend!</body></note>

谢谢大家。

【问题讨论】:

    标签: xml c#-4.0


    【解决方案1】:

    您可以使用 Xlinq:

    XElement.Parse(str).ToString(SaveOptions.DisableFormatting)
    

    【讨论】:

    • 我发现它正在从输出中删除“”。
    • @midspace:使用XDocument.Parse()
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-29
    • 2020-05-26
    • 2012-09-18
    • 2016-06-23
    • 2015-02-01
    • 1970-01-01
    相关资源
    最近更新 更多