如何使用PHP中的DOM解析器创建此XML?
问题描述:
如何使用PHP中的DOM解析器创建此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>cornerRadius</key>
<real>5</real>
</dict>
答
你应该使用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>
在这里你可以阅读更多有关DOM文档:
http://www.php.net/manual/pl/class.domdocument.php
+0
您链接到波兰语翻译,英语将是http://www.php.net/manual/en/class.domdocument.php – ThW
的问题是不是可读它是[当前版本](http://stackoverflow.c OM /修改/3分之21812410)。要格式化代码,请选择代码,然后按Ctrl + K(或编辑工具箱中的“{}”按钮)。 –