11.07.2015 Views

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CHAPTER 20 • WEB SERVICESwww.it-ebooks.infoJake BarnesLady Brett AshleyRobert CohnMike CampbellUsing XPath to Retrieve Node InformationXPath is a W3C standard that offers an intuitive, path-based syntax for identifying XML nodes.SimpleXML offers a method called xpath() for doing so, and its prototype follows:array simplexml_element->xpath(string path)XPath also offers a set of functions for selectively retrieving nodes based on value. For example,referring to the books.xml document, you could use the xpath() method to retrieve all author nodesusing the expression /library/book/author:xpath("/library/book/author");foreach($authors AS $author) {echo "$author";}?>This example returns the following:Jane AustenAlberto MoraviaErnest HemingwayYou can also use XPath functions to selectively retrieve a node and its children based on a particularvalue. For example, suppose you want to retrieve all book titles where the author is named “ErnestHemingway”:xpath("/library/book[author='Ernest Hemingway']");echo $book[0]->title;?>This example returns the following:The Sun Also Rises424

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

Saved successfully!

Ooh no, something went wrong!