HomePHP Loading XML Strings with simpleXML in PHP 5
Loading XML Strings with simpleXML in PHP 5
Are you looking forward to learning about loading XML data strings, as well as searching and accessing nodes? Then this is the tutorial you’ve been waiting for since last week! Welcome to the second part of the series “Working with simpleXML in PHP 5.” This three-part series introduces the most important features of the “simpleXML” extension that comes with PHP 5, and shows by several hands-on examples how to implement the handy set of XML-parsing functions that are included in this library.
For those of you who didn't read the first article, let me put you quickly in the right context. Over the course of the previous tutorial, I explained the basics of the excellent "simpleXML" library included with PHP 5, introducing the use of the "simplexml_load_file()" function. This can be remarkably useful if you need to add basic XML parsing capabilities to your PHP 5 applications, but don't wish to develop a full-blown XML parser.
Based on the capacity provided by the "simplexml_load_file()" function, I went through the development of different practical examples, aimed at illustrating how a specific XML file can be basically parsed in different ways, including the loading of XML data onto objects, as well as the localization (and eventually the extraction) of particular nodes within a file. In addition, due to the ubiquitous nature of this extension, I showed how to build a basic XML parsing class, which worked as a simple wrapper for the "simplexml_load_file()" function, allowing the retrieval of different nodes contained within an XML file, and more.
Hopefully, all the examples shown in the previous article have provided you with the right pointers to start using the "simpleXML" library with only minor hassles, therefore in this second tutorial, I'll continue exploring other helpful functions, focused primarily on loading XML data strings, as well as searching and accessing nodes.
Provided that all the topics that I mentioned before already caught your attention, let's continue exploring the handy functions included within the "simpleXML" extension. Let's get started!