Introducing SimpleXML in PHP 5 (
Page 1 of 4 )
In the first article of a three-part series, you will learn the basics of using the “simplexml” extension that comes with PHP 5. This library is primarily focused on parsing simple XML files, and can save you a lot of work.Introduction
For those of you who have been using PHP 5 for a while, the numerous improvements introduced into the Zend engine have brought significant advantages that help to accelerate the development of Web applications. Intermediate and experienced developers probably will tell you nice things about the new object model, and the implementation of exceptions, in addition to the set of functions aimed at processing XML data in different ways. And of course, the list of new features goes on and on.
However, recently I discovered a little jewel hidden behind the tons of big improvements that come with PHP 5: a small and powerful library called “simpleXML.” Indeed, if you’re currently working on a project that requires handling XML data in a basic manner, this extension might eventually suit your needs, without your having to develop a full-featured XML parser.
Definitely, one of the best things about “simpleXML” is how easily it performs basic tasks, such as reading XML files, extracting data from XML strings, comparing and replacing nodes, and so forth. Based on this simplicity, you can develop a decent XML parsing application without having to make a huge effort, or even combine all these cool features with the functionality of AJAX, in order to construct a full-fledged application that uses the best of client and server-based scripting languages.
In response to all the exciting features that I mentioned before, in this three-part series I’ll be taking a close look at the most important functions of the “simpleXML” extension, using numerous code samples and clear explanations to put them in context, so you can understand how they work.
At the end of the series, you should be equipped with the proper background to start using “simpleXML” in your own PHP 5 applications.
Having now defined the goals of this series, let’s find out together how to use the “simpleXML” library with PHP 5. Let’s get going!
| | Discuss Introducing SimpleXML in PHP 5 | | | | | | | In the course of this first article, you'll learn how to use some of the most... | | | | | | I enjoyed your article. All the xml files you used were stored on the server, is... | | | | | | Hello JET:
I'm happy to know you enjoyed my article. Thank you. Now, in response... | | | | | | Nice article, I only found an mistake during the countNodes function.
The $nodeName... | | | | | | I'm glad to know that the article has been useful to you. Now, with reference to... | | | | | | Hi,
this solution doesn't work for me.
if I remove an 'address' element from... | | | | | | Hello Bob,
Thank you for your comments. I tested the method and works just fine.... | | | | | | Hi,
thank you for your answer.
Tested it again and still get the same output... | | | | | | Hi Bob,
Thank you for your feedback. Okay, there was a small bug on the method.... | | | | | | Hi,
thank you for your answer.
In the meantime I also found a working... | | | | | | Hi Bob,
I'm glad to see you found an alternative solution to the one I provided... | | | | | | can you share how you removed an entire node?
thx
walter | | | | | | Thanks for the comments on my PHP article. Basically, to remove a node you might... | | | | | | Hey there!!
Excellent resource on XML :) | | | | | | Thanks for the kind words on my PHP article. It's good to know you found it... | | | | | | >>> Post your comment now! | | | | | |
|
 |