如何在PHP中使用DOM Parser创建此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>
答案 0 :(得分:2)
您应该使用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>
在这里,您可以阅读有关DOMDocument的更多信息:
http://www.php.net/manual/pl/class.domdocument.php