去掉libxml2 c中xmldocument和根节点之间的白色space

Remove white space between xmldocument and root node in libxml2 c

我使用 libxml2 C 创建了一个 xml 树。例如,我的输出是

<?xml version="1.0" encoding="UTF-8"?>`  

<Ocean>                                 

    <Sea>Pacific</Sea>

    <Lake>Tahoe</Lake>

</Ocean>

我已经使用 xmlDocDumpMemoryEnc(....) 删除节点缩进,然后我的输出是

<?xml version="1.0" encoding="UTF-8"?>

<Ocean><Sea>Pacific</Sea><Lake>Tahoe</Lake></Ocean>

但是我希望输出为

<?xml version="1.0" encoding="UTF-8"?><Ocean><Sea>Pacific</Sea><Lake>Tahoe</Lake></Ocean>

我搜索了 libxml2 模块函数以删除 xml 文档和根节点之间的白色 space,并找到了 none。我非常感谢对此的任何帮助。

虽然按照标准 not mandated,但通常在 XML 声明后换行。

libxml2 有这个新行 hardcoded, so you are left with either, having libxml2 skip the XML declaration and prepending it yourself or output it and shifting 它可以覆盖换行符。