当年话下
Gumbo的解决方案可以解决问题。您可以使用上面的simpleXml,然后在最后添加它以回显和/或使用格式保存它。下面的代码回显并将其保存到文件中(请参阅代码中的注释并删除任何您不想要的内容)://Format XML to save indented tree rather than one line$dom = new DOMDocument('1.0');$dom->preserveWhiteSpace = false;$dom->formatOutput = true;$dom->loadXML($simpleXml->asXML());//Echo XML - remove this and following line if echo not desiredecho $dom->saveXML();//Save XML to file - remove this and following line if save not desired$dom->save('fileName.xml');