Want to learn how to get the most out of the “simpleXML” extension that comes bundled with PHP 5? Welcome to the last part of the series “Working with simpleXML in PHP 5.” In three tutorials, this series covers topics ranging from the basics of parsing XML files with this library, to performing advanced tasks, such as searching, extracting and replacing nodes, and interoperating with the XML DOM.
In the previous article in this series I demonstrated how XML is used to make remote procedure calls with XML-RPC in PHP. This article will focus on SOAP and WSDL (both of which use XML as their underlaying method of describing data) and demonstrate how a PHP script can act as a SOAP client and auto-magically discover detailed information about a web service.
Although the acronym SAX stands for Simple Access (or API) to XML, it is not that easy, that everybody instantly is able to use it. PHP provided a SAX-based parser using the xml_* functions since PHP 3.0.6, but only since PHP5 provides a wider range of XML APIs PHP and XML are getting the attention they deserve. This tutorial will show you how to use XML_Parser, an object oriented wrapper around the native PHP extension, which makes processing XML documents with PHP4 easy as cake.
SAX is an event based parser. That means that the XML document is traversed character by character and whenever the parser finds an entity (like an opening or closing tag, a processing instruction or only plain character data) it will trigger events. You PHP script may then catch these events by supplying PHP functions or methods as callbacks.
I had some time to kill and a silly problem to solve, which means here’s some more SimpleXML fun for you:
The Problem: It’s not really a “problem,” but FeedBurner’s FeedCountTM image is a rigid 88 pixels wide, and I wanted to include it on my homepage under the “syndicate” heading, an area that I’ve defined in my template as having only 80 pixels in width. The 88 pixels were throwing things off, so I used the width attribute of the HTML img tag to solve the problem. Unfortunately, it just squeezes the image, making the text in it appear fuzzy.
I've been working with SimpleXML a fair amount lately, and have run into an issue a number of times with character encodings. Basically, if a string has a mixture of UTF-8 and non-UTF-8 characters, SimpleXML barfs, claiming the "String could not be parsed as XML."
I was very excited today while glancing through the code in ext/simplexml/simplexml.c to find some, as of yet, undocumented methods in PHP’s SimpleXMLElement class. This discovery came after I’ve spent several hours over the last couple of nights banging my head against the desk to figure out a way to create a class that extends SimpleXMLElement and adds a new method for adding a child, which would have to use DOM in order to work—or so I thought.
This is the second half of an article that began last week on XML-RPC and PHP. This week we put together the PHP RPC server and learn more about the emailValidator_validate function!
In the first part of this series, we took a look at how PHP 5 can be used to manipulate and parse XML files. In this installment, we are going to focus on Ajax, one of the most useful and topical applications of XML.
Initially, we are going to introduce Ajax and learn how to use the XMLHTTP object provided by most modern web browsers to create a live email validation form. Then we will pick up where we left off with the theme of XML and introduce XSLT, which we will use to transform our library XML from the previous article into valid XHTML code.