This series of articles will focus on XML, its applications in modern day web development and how PHP fits into this niche. In this article, we will focus specifically on the tools provided to us by PHP which enable us to manipulate XML data sources.
Myriad techniques are available for reading and writing XML in PHP. This article presents three methods for reading XML: using the DOM library, using the SAX parser, and using regular expressions. Writing XML using DOM and PHP text templating will also be covered.
Now that PHP 5 is becoming more and more prevalent over its predecessors, some really good books that cover PHP need revisions. Nowhere is this more true than with XML-related topics, where PHP 5 has a completely different way of working with XML — and, in fact, the mechanisms from PHP 4 will no longer work.
Ever thought SimpleXML is too simple? Did you know, you can easily extend the SimpleXMLElement class?
There’s a lot about SimpleXML, PHP5’s new API for accessing the contents of XML documents, in SitePoint’s recently-published book No Nonsense XML Web Development With PHP, but one thing it doesn’t cover is how to use SimpleXML with a document that makes use of XML Namespaces.
I've been interested in XPath lately. I am investigating using XPath to query 'Sloppy' HTML documents instead of XML documents for the purpose of writing web tests. I've been using a CSS like syntax cobbled together with nasty regular expressions that don't work in all cases. For example:
$this->assertTextInElement('div.Status', 'The Category has been added to the database.');
I've found that there is a certain synergy between the tests and the CSS syntax. The things that you want to test also tend to be the things that you want to style. I'm not sure that the XPath syntax will be as well suited to this purpose. On the other hand, XPath is certainly more available and more capable.
So today, as a learning exercise, I hacked together a toy interpreter for XPath expressions in native PHP.
The purpose of this article is to demonstrate through a series of baby steps just how easy it is to use the XMLHttpRequest object.
In order to complete this tutorial you should have some basic PHP, MySQL and JavaScript experience. That said, the PHP programming in these examples is so basic that if you do not have PHP experience, it may still be possible for you to look at the PHP code and apply the functionality to your weapon of choice, be it PERL, ASP, or JSP.
You can access portions of XML documents in PHP using the W3C Xpath standard
XPath is a language that allows you to address parts of an XML document, making XSLT transformations practically necessary. It also makes it an invaluable tool for managing XML data in applications such as Web applications.
Unless you've been hiding in a cave for the last few years, you've heard about XML - it's the toolkit that more and more Web publishers are switching to for content markup. You may even have seen an XML document in action, complete with user-defined tags and markup, and you might have wondered how on earth one converts that tangled mess of code into human-readable content.
The answer is, not easily.
While PHP has included support for the two standard methods of parsing (read: making sense of) XML - SAX and DOM - since version 4.0, the complexity and inherent geekiness of these methods often turned off all but the most dedicated XML developers. All that has changed, however, with PHP 5.0, which introduces a brand-spanking-new XML extension named SimpleXML that takes all (and I do mean all) the pain out of processing XML documents. Keep reading, and find out how.
As mentioned in a previous post, someone already wrote a script for making the migration to from PHP 4 to PHP 5 easier, if you're using the domxml extension of PHP 4. Unfortunately the site went soon offline and the script wasn't recoverable anymore. But now, Alexandre Alapetite made a new attempt and published his domxml-php4-to-php5.php script.








