note 87361 modified in function.simplexml-element-addAttribute by danbrown
| From: | danbrown@php.net | Date: | Wed, 16 Sep 2009 15:47:10 +0000 |
| Subject: | note 87361 modified in function.simplexml-element-addAttribute by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-160665@lists.php.net to get a copy of this message | ||
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');
?>
--was--
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.
$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:
$simplexml->addAttribute('xsi:type', 'AmazonCustomerByEmail', 'http://www.w3.org/2001/XMLSchema-instance');
http://php.net/manual/en/function.simplexml-element-addAttribute.php