首页 > 解决方案 > 订购 Xml

问题描述

我有一个 xml,它在和没有适当缩进的标签之间有空格。如何重新排序它..?

我想要的输出是正确缩进的 XML 文档,中间没有空行

<Document>
    <another>
        <tag1>
            <content>a</content> <!-- might be other nested tags inside <content></content>-->
<content>b</content> <!--might be other nested tags inside <content></content>-->
            <content>c</content> <!--might be other nested tags inside <content></content>-->
        </tag1>

        <tag_b>
            <things>d</things> <!--might be other nested tags inside <things></things>-->
            <things>e</things> <!--might be other nested tags inside <things></things>-->

            <tag_C>
                <!-- other nested tags here -->
            </tag_C>
        </tag_b>

        <tag_b>
<things>f</things> <!--might be other nested tags inside <things></things>-->
            <things>g</things> <!--might be other nested tags inside <things></things>-->

            <tag_C>
                <!-- other nested tags here -->
            </tag_C>
        </tag_b>

        <tag_b>
<things>f</things> <!--might be other nested tags inside <things></things>-->
                     <things>g</things> <!--might be other nested tags inside <things></things>-->

            <tag_C>
                <!-- other nested tags here -->
            </tag_C>
        </tag_b>
    </another>

标签: pythonpython-3.x

解决方案


推荐阅读