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.

www.it-ebooks.infoCHAPTER 20 • WEB SERVICES[2]=>object(SimpleXMLElement)#4 (3) {["title"]=>string(18) "The Sun Also Rises"["author"]=>string(16) "Ernest Hemingway"["description"]=>string(55) "The masterpiece that launched Hemingway'scareer."}}}Note that dumping the XML will not cause the attributes to show. To view attributes, you need touse the attributes() method, introduced later in this section.Loading XML from a StringIf the XML document is stored in a variable, you can use the simplexml_load_string() function to read itinto the object. Its prototype follows:object simplexml_load_string(string data)This function is identical in purpose to simplexml_load_file(), except that the lone input parameteris expected in the form of a string rather than a file name.Loading XML from a DOM DocumentThe Document Object Model (DOM) is a W3C specification that offers a standardized API for creating anXML document, and subsequently navigating, adding, modifying, and deleting its elements. <strong>PHP</strong>provides an extension capable of managing XML documents using this standard, called the DOM XMLextension. You can use the simplexml_import_dom() function to convert a node of a DOM document intoa SimpleXML node, subsequently exploiting use of the SimpleXML functions to manipulate that node.Its prototype follows:object simplexml_import_dom(domNode node)Parsing XMLOnce 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.Learning More About an ElementXML attributes provide additional information about an XML element. In the sample XML documentpresented in Listing 20-4, only the author node possesses an attribute, namely gender, used to offer421

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

Saved successfully!

Ooh no, something went wrong!