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

Evert Pot:
An XML library for PHP you may not hate.
Apr 02, 2015 @ 16:13:55

Evert Pot has posted about an XML library you may not hate, the sabre/xml library.

If you are writing or consuming API's in PHP, chances are that you need to work with XML. In some cases you may even prefer it. You may have started with SimpleXML and after a while switched to using the DOM after realizing SimpleXML is really not that simple if you strictly use xml namespaces everywhere.

For writing XML, you may have found that using the DOM requires far too much code, or you may simply generate your XML by echoing strings, knowing that it may not be the best idea. sabre/xml hopes to solve your issues, by wrapping XMLReader and XMLWriter, and providing standard design patterns.

He includes some example code showing how it works, extending the XMLReader/Writer functionality with a simplified interface. He includes examples of both writing a new XML file or reading in and working with the contents of a given one. He does point out one issue, though - the library cannot really read in XML contents, modify it and send it back out (it's a "single pass" system). He wraps up the post talking about the various interfaces and elements in the library and some of the overall benefits it provides.

tagged: xml library xmlreader xmlwriter interface simple

Link: http://evertpot.com/an-xml-library-you-may-not-hate/


Trending Topics: