11.07.2015 Views

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CHAPTER 20 • WEB SERVICESwww.it-ebooks.infoinformation about the author’s gender. You can use the attributes() method to retrieve theseattributes. Its prototype follows:object simplexml_element->attributes()For example, suppose you want to retrieve the gender of each author:book as $book) {printf("%s is %s. ", $book->author, $book->author->attributes());}?>This example returns the following:Jane Austen is female.Alberto Moravia is male.Ernest Hemingway is male.You can also directly reference a particular book author’s gender. For example, suppose you want todetermine the gender of the author of the second book in the XML document:echo $xml->book[2]->author->attributes();This example returns the following:maleOften a node possesses more than one attribute. For example, suppose the author node looks likethis:Jane AustenIt’s easy to output the attributes with a for loop:foreach($xml->book[0]->author->attributes() AS $a => $b) {printf("%s = %s ", $a, $b);}This example returns the following:gender = femaleage = 20422

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!