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.

www.it-ebooks.infoCHAPTER 20 • WEB SERVICESCreating XML from a SimpleXML ObjectThe asXML() method returns a well-formed XML 1.0 string based on the SimpleXML object. Its prototypefollows:string simplexml_element->asXML()An example follows:asXML());?>This example returns the original XML document, except that the newline characters have beenremoved and the characters have been converted to their corresponding HTML entities.Learning About a Node’s ChildrenWhat happens if you are interested only in a particular node’s children? Using the children() method,retrieving them becomes a trivial affair. Its prototype follows:object simplexml_element->children()Suppose, for example, that the books.xml document is modified so that each book includes a cast ofcharacters. The Hemingway book might look like the following:The Sun Also RisesErnest HemingwayThe masterpiece that launched Hemingway's career.Jake BarnesLady Brett AshleyRobert CohnMike CampbellUsing the children() method, you can easily retrieve the characters:book[2]->cast->children() AS $character) {echo "$character";}?>This example returns the following:423

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

Saved successfully!

Ooh no, something went wrong!