note 87361 deleted from simplexmlelement.addAttribute by danbrown
| From: | danbrown@php.net | Date: | Fri, 28 Jan 2011 14:34:53 +0000 |
| Subject: | note 87361 deleted from simplexmlelement.addAttribute by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-176471@lists.php.net to get a copy of this message | ||
Note Submitter: Ryan Parman (Skyzyx)
----
It took me some time to finally figure this out since nobody had blogged about it or documented it
anywhere that I could find.
I was trying to define a namespace and use a namespace as attributes like so:
<Grantee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:type="AmazonCustomerByEmail">
<EmailAddress>user@company.com</EmailAddress>
</Grantee>
I was using the following thinking that when they asked for the namespace, they actually meant the
namespace.
<?php
$simplexml->addAttribute('xsi', 'http://www.w3.org/2001/XMLSchema-instance',
'xmlns');
$simplexml->addAttribute('type', 'AmazonCustomerByEmail', 'xsi');
?>
Instead, they want the name to have the namespace attached, and to pass the namespace URL as the
third parameter. Also by doing this, the xmlns:xsi="url" gets added automatically. I had
no idea.
After an hour of non-stop digging, I dug through the CVS commit messages and found a clue which led
me to this working code:
<?php
$simplexml->addAttribute('xsi:type', 'AmazonCustomerByEmail', 'http://www.w3.org/2001/XMLSchema-instance');
?>