qJerry: write less, do more. Now in PHP.
Somehow imperceptibly on Habré the appearance of an interesting, in my opinion, library was published.
qJerry is an XML document library 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.
In the development of modern web applications, XML, PHP and JavaScript are often found together in order to realize a miracle called AJAX. However, such a meeting can cost a developer a lot of time and nerves if he does not arm himself with good tools. One such tool that makes our lives easier is the jQuery library. It will not be an exaggeration to say that it is so convenient to use, and the principles underlying it are so simple and ingenious that they want to be moved beyond JavaScript and used wherever you have to work with XML. The qJerry library is just such an attempt to project the approach used by jQuery in PHP.
Undoubtedly, the most pleasant feature of jQuery is that the code written with its help is several times smaller than the functionally similar code written using standard tools, not to mention significant time savings. Like jQuery, which saved honest JavaScript programmers from a bunch of unnecessary work, qJerry is trying to do the same for those who write in PHP. Although qJerry is primarily aimed at web application developers, 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 APIs of the jQuery library, familiar to many web developers. There are several important differences:
Suppose we need to create an XML document like this:
We do it using the traditional DOM: And now the same thing using qJerry: It's not difficult to see that qJerry makes working with XML much easier than the DOM, even in the most trivial case, not to mention the complex manipulation of multiple queries and tree changes XML Well, actually the library: qJerry
About qJerry library
qJerry is an XML document library 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.
In the development of modern web applications, XML, PHP and JavaScript are often found together in order to realize a miracle called AJAX. However, such a meeting can cost a developer a lot of time and nerves if he does not arm himself with good tools. One such tool that makes our lives easier is the jQuery library. It will not be an exaggeration to say that it is so convenient to use, and the principles underlying it are so simple and ingenious that they want to be moved beyond JavaScript and used wherever you have to work with XML. The qJerry library is just such an attempt to project the approach used by jQuery in PHP.
Undoubtedly, the most pleasant feature of jQuery is that the code written with its help is several times smaller than the functionally similar code written using standard tools, not to mention significant time savings. Like jQuery, which saved honest JavaScript programmers from a bunch of unnecessary work, qJerry is trying to do the same for those who write in PHP. Although qJerry is primarily aimed at web application developers, 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 APIs 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. return a lot of added items; you can return to the original set using the end () method;
- methods for working with events and effects, as well as other methods specific to the native jQuery environment, browser, are not supported, because they do not make sense in the context of a server-side programming language;
- the names of the empty () and clone () methods are changed to clear () and copy (), respectively, to avoid conflicts with reserved PHP words;
- qJerry is focused on working with any number of arbitrary XML documents, while jQuery works mainly with one - the web page itself.
QJerry examples
Simple example
Suppose we need to create an XML document like this:
We do it using the traditional DOM: And now the same thing using qJerry: It's not difficult to see that qJerry makes working with XML much easier than the DOM, even in the most trivial case, not to mention the complex manipulation of multiple queries and tree changes XML Well, actually the library: qJerry
$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();
q('items')->append('item')->attr('id', '1')->end()->append('item')->attr('id', '2')->dump();