News Feed
Sections




News Archive
feed this:

Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Christian Schaefer's Blog:
Simply iterate over XML with plain PHP using little memory and CPU
March 10, 2011 @ 08:11:31

In a new post to his Test.ical.ly blog Christian Schaefer shows you how to iterate over XML in a more efficient way with the help of the XMLReader and Iterator features that come with PHP.

One of the things I have been working on lately was a simple XML parser. It's a simple XML structure in my case though it could be more complex without much change. My solution was a quite powerful yet simple combination of XMLReader and the Iterator interface.

He includes a sample XML document similar to the one he was working with and shows how XMLReader can handle it, keeping only the currently needed information in memory at one time. His sample class (CustomXml) loads the file and defines all of the iterator methods to work with the data like "next", "prev" and "rewind".

0 comments voice your opinion now!
iterate xml xmlreader iterator memory tutorial


PHPBuilder.com:
A Quick PHP XMLWriter Class Tutorial XML & RSS
January 19, 2009 @ 11:19:52

The PHPBuilder.com has posted today looking to introduce you to a powerful XML creation tool in PHP5 installations - XMLWriter.

They jump right in and show it in action by creating a simple RSS document with one element inside. A call to the flush() method on your XMLWriter object is all it takes to output the XML.

They also change things up and bit and swap out the procedural code for a more object-oriented approach with a constructor that sets up the object and adds in some of the common RSS information. Their addItem() method is called to add in a sample item (in this case, an entry for a CD player product) and _endRSS() closes things off and runs that flush() to send it all back out.

You can find out more about XMLWriter (and its sister, XMLReader) in the PHP manual.

0 comments voice your opinion now!
xmlwriter tutorial rss class oop php5 xmlreader


Jeremy Johnstone's Blog:
PHP parser for OS X plist XML files
October 27, 2008 @ 09:35:56

Jeremy Johnstone has come up with a simple plist xml parser. The plist format is what iTunes (and some other application) uses for its library files.

Normally SimpleXML is enough to handle most XML parsing needs, but the plist XML format is just broken enough to make parsing it with SimpleXML virtually impossible. Since I hadn't played with XMLReader much, I thought it would be a good chance to give it a spin. For the anxious types, the code is available on github in my php_class_lib project, so dig right in.

His parser takes in the name of the file to fetch and a parser() method is called to do the actual work. The contents of the file are returned as an array (he includes a print_r() of that output too).

1 comment voice your opinion now!
osx parse xmlreader plist xml file tutorial github


Christian Weiske's Blog:
Importing huge XML files using PHP5 - efficiently and conveniently
August 25, 2008 @ 09:34:38

Christian Weiske has a quick tip on how to get larger XML files to pull into PHP5 and be usable:

At work I had the task to implement the synchronization between an online shop and a commodity management system. Data exchange format was XML - one big XML file for all of the products (some thousands with dozens of attributes). Big question: How do I import the file in a way that is most convenient for me as a programmer - and without exceeding the machine's RAM when loading a 1 GiB file?

The newer alternatives both use the same technology (DOM and SimpleXML - with DOM behind it) so he goes more "low tech" than that and opts for the XMLReader extension to pull in the large amounts of data. Available in PHP5, the XMLReader extension, which he combines with an Iterator from the SPL to makes for a simple, quick little parser.

0 comments voice your opinion now!
import xml file php5 efficient convenient xmlreader spl iterator


Zend Developer Zone:
XML and PHP 5
August 01, 2007 @ 10:13:00

The Zend Developer Zone has a new tutorial posted looking at PHP5 and the new XML tools that it has to offer - as broken up into categories:

Things are a bit different using XML in PHP 5. In a similar scenario, you could use one of the new native extensions, like DOM or SimpleXML, to manipulate the XML data tree. This tree can then be passed directly to and used by the XSL extension without incurring any additional overhead. There is no serialization nor copying involved; ext/xsl is able to work directly with the XML tree it is given, resulting in a significant improvement in use of system resources as compared to coding a similar task in PHP 4. So now that you have an idea why XML support got a face lift, you might like to know about the different tools available to you.
0 comments voice your opinion now!
xml php5 tutorial introduction dom xsl xmlreader xmlwriter simplexml xml php5 tutorial introduction dom xsl xmlreader xmlwriter simplexml



Community Events





Don't see your event here?
Let us know!


language community wordpress application symfony introduction list library developer release interview series install configure bugfix podcast api laravel threedevsandamaybe code

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework