CHAPTER 7 SIMPLEXML 257 When an attribute
CHAPTER 7 SIMPLEXML 257 When an attribute is being written to and does not exist on the element, the attribute is automatically created with the content specified by the string to which it is being set. In this instance, the firstname element originally contained no attributes. Writing the string Mr. to an attribute named prefix, the prefix attribute was created on the firstname element and its value set to the value of the supplied string. Removing Attributes Again, you can use the function unset() to remove attributes from elements, just as you remove elements from the tree: $book = simplexml_load_file(’sxml.xml’); $book->bookinfo->author->firstname[”prefix”] = “Mr.”; print $book->bookinfo->author->firstname->asXML().”nn”; unset($book->bookinfo->author->firstname[”prefix”]); print $book->bookinfo->author->firstname->asXML();
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Clan Web Hosting services