【发布时间】:2013-09-14 09:46:20
【问题描述】:
如何使用SimpleXMLElement 将属性添加到更深层的子笔记?例如,
$xml = new SimpleXMLElement('<xml/>');
$response = $xml->addChild('response');
$response->addChild('error');
$response->addAttribute('elementid', 100);
$response->addAttribute('message', 'You must not leave this field empty!');
Header('Content-type: text/xml');
print($xml->asXML());
我明白了,
<xml>
<response elementid="100" message="Key name - You must not leave this field empty!">
<error />
</response>
</xml>
但其实我想要,
<xml>
<response>
<error elementid="100" message="Key name - You must not leave this field empty!" />
</response>
</xml>
有可能吗?
【问题讨论】: