488 CHAPTER 20 (Remote web server) WEB SERVICES simplexml_load_string() object
Friday, November 30th, 2007488 CHAPTER 20 WEB SERVICES simplexml_load_string() object simplexml_load_string (string data) If the XML document is stored in a variable, you can use the simplexml_load_string() function to read it into the object. This function is identical in purpose to simplexml_load_file(), except that the lone input parameter is expected in the form of a string rather than a file name. simplexml_import_dom() object simplexml_import_dom (domNode node) The Document Object Model (DOM) is a W3C specification that offers a standardized API for creating an XML document, and subsequently navigating, adding, modifying, and deleting its elements. PHP provides an extension capable of managing XML documents using this standard, titled the DOM XML extension. You can use this function to convert a node of a DOM document into a SimpleXML node, subsequently exploiting use of the SimpleXML functions to manipulate that node. SimpleXML Methods Once an XML document has been loaded into an object, several methods are at your disposal. Presently, four methods are available, each of which is introduced in this section. attributes() object simplexml_element->attributes() XML attributes provide additional information about an XML element. In the sample XML document in Listing 20-4, only the author node possesses an attribute, namely gender, used to offer information about the author s gender. You can use the attributes() method to retrieve these attributes. For example, suppose you want to retrieve the gender of each author: book as $book) { echo $book->author.” is “.$book->author->attributes().”.
“; } ?> This example returns: Jane Austen is female. Alberto Moravia is male. Ernest Hemingway is male.
We recommend cheap and reliable webhost to host and run your web applications: Coldfusion Web Hosting services.