如何在 AS3 中 minimize/minify 一个 XML 文档

How can I minimize/minify an XML document in AS3

我有一个 AS3 生成的 XML 对象,我想在通过网络将其发送到远程系统之前 "minimize" 或 "minify"。

我无法在 AS3 文档中找到任何内容来解决这个问题。我争论过正则表达式替换......但这是一个容易出现一百万个错误的糟糕解决方案。

有没有人有任何替代建议?

示例(原始):

trace(xml.toString());

<Foo>
    <Bar>
        <Property>Property One</Property>
        <Value />
    </Bar>
    <Bar>
        <Property>Property Two</Property>
        <Value>Value Two</Value>
    </Bar>
    ...
    ...
</Foo>

示例(期望):

trace(minify(xml.toString()));

<Foo><Bar><Property>Property One</Property><Value /></Bar><Bar><Property>Property Two</Property><Value>Value Two</Value></Bar>...</Foo>

如果您只想删除空格字符,请使用 prettyPrinting = false:

XML.prettyPrinting = false;
trace(xml.toXMLString());
XML.prettyPrinting = true;