如何使用 向更深的子注释添加属性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>
是否可以?