如何在PHP中使用DOM解析器创建此XML?

如何在PHP中使用DOM解析器创建此XML?,php,xml,Php,Xml,如何在PHP中使用DOM解析器创建此XML <dict> <key>CGBlendMode</key> <integer>1000</integer> <key>backgroundColorRGBA</key> <string>RGBA:0.000000,1.000000,1.000000,1.000000</string> <key>corne

如何在PHP中使用DOM解析器创建此XML

<dict>
   <key>CGBlendMode</key>
   <integer>1000</integer>
   <key>backgroundColorRGBA</key>
   <string>RGBA:0.000000,1.000000,1.000000,1.000000</string>
   <key>cornerRadius</key>
   <real>5</real>
</dict>

CGBlendMode
1000
背景颜色RGBA
RGBA:0.000000,1.000000,1.000000,1.000000
转弯半径
5.

您应该使用PHP DOMDocument对象

$dom = new DOMDocument('1.0', 'utf-8');
$element = $dom->createElement('test', 'This is the root element!');
// We insert the new element as root (child of the document)
$dom->appendChild($element);
echo $dom->saveXML();
给出输出:

<?xml version="1.0" encoding="utf-8"?>
<test>This is the root element!</test>

这个问题在书中是不可读的。要设置代码格式,请选择代码,然后按Ctrl+K(或编辑工具箱中的
{}
按钮)。如果链接到波兰语翻译,则将使用英语
 http://www.php.net/manual/pl/class.domdocument.php