HomePHP Using XPath, SOAP, and More with Web Services
Using XPath, SOAP, and More with Web Services
In this fourth part of a five-part series on Web Services, you'll learn about SimpleXML objects, SOAP, and more. This article is excerpted from chapter 20 of the book Beginning PHP and Oracle: From Novice to Professional, written by W. Jason Gilmore and Bob Bryla (Apress; ISBN: 1590597702).
This example returns the original XML document, except that the newline characters have been removed and the characters have been converted to their corresponding HTML entities.
Learning About a Node’s Children
Often you might be interested in only a particular node’s children. Using thechildren()method, retrieving them becomes a trivial affair. Its prototype follows:
object simplexml_element->children()
Suppose for example that thebooks.xmldocument is modified so that each book includes a cast of characters. The Hemingway book might look like the following:
<book> <title>The Sun Also Rises</title> <author gender="male">Ernest Hemingway</author> <description>The masterpiece that launched Hemingway's career.</description> <cast> <character>Jake Barnes</character> <character>Lady Brett Ashley</character> <character>Robert Cohn</character> <character>Mike Campbell</character> </cast> </book>
Using thechildren()method, you can easily retrieve the characters: