Somehow, invisibly on Habré, the appearance of an interesting, in my opinion, library passed.
About qJerry library
qJerry is a library for working with XML documents written in PHP. The main mission of qJerry is to make working with XML more comfortable than standard PHP tools, such as the DOM extension, allow.
When developing modern web applications, XML, PHP and JavaScript are often found together in order to realize the miracle called AJAX. However, the developer of such a meeting can cost a lot of time and nerves if he does not arm himself with good tools. One such tool that makes life easier for us is the jQuery library. It would not be an exaggeration to say that it is so easy to use, and the principles underlying it are so simple and ingenious that you want to take them beyond the bounds of JavaScript and use them everywhere you have to work with XML. The qJerry library is just such an attempt to project on the PHP approach used in jQuery.
')
Undoubtedly, the most pleasant feature of jQuery is that the code written with it is several times smaller than the functionally similar code written using standard tools, not to mention a significant time saving. Like jQuery, which saved honest JavaScript programmers from a lot of extra work, qJerry tries to do the same for those who write in PHP. And while qJerry is primarily aimed at web application creators, it can be useful to anyone who has to work with XML in PHP.
qJerry is a kind of wrapper for the DOM extension and almost completely copies the behavior and API of the jQuery library, familiar to many web developers. There are several important differences:
- XPath is used as the query language, jQuery selectors are not supported;
- methods like append (), before (), etc. returns many added items; You can return to the original set using the end () method;
- methods for working with events and effects, as well as other jQuery browser-specific native environments, are not supported because they do not make sense in the context of a server-side programming language;
- the names of the methods empty () and clone () are changed to clear () and copy (), respectively, in order to avoid conflicts with PHP reserved words;
- qJerry is designed to work with any number of arbitrary XML documents, whereas jQuery works primarily with one - the actual web page.
QJerry usage examples
Simple example
Suppose we need to create such an XML document:
<? xml version = "1.0" encoding = "UTF-8"?>
<items> <item id = "1" /> <item id = "2" /> </ items>
We do this using the traditional DOM:
$dom = new DOMDocument('1.0', 'UTF-8');
$dom->appendChild($dom->createElement('items'));
$dom->documentElement->appendChild($dom->createElement('item'))->setAttribute('id', '1');
$dom->documentElement->appendChild($dom->createElement('item'))->setAttribute('id', '2');
echo $dom->saveXML();
And now the same thing with qJerry:
q('items')->append('item')->attr('id', '1')->end()->append('item')->attr('id', '2')->dump();
It's not hard to see that qJerry makes working with XML much easier than DOM, even in the most trivial case, not to mention the complex manipulations with multiple queries and changes to the XML tree.
Well, actually the library:
qJerry