Learning PHP, XML - addattribute how to use?

Smith

New member
I currently have a PHP script that is as follows . . .

<?php
$xml = '<store>
<category id="fiction">
<book>
<title>twilight</title>
<author>Stephinie Mayer</author>
<usbn>199939</usbn>
</book>
<book>
<title>The Bikers</title>
<author>Alex R.Stuart</author>
<usbn>77689</usbn>
</book>
</category>
</store>
';
$sxe = new SimpleXMLElement($xml);

$sxe->addAttribute('type', 'documentary');

echo $sxe-> asXML();

?>

I am trying to find out what the "addattribute" is doing. Can you please show and example were I can see the addattribute having an effect on the XML created in the SimpleXMLElement command please?
Thanks Dennis, but I don't understand. I know what a function is but how do the two link?
 
Back
Top