phpDocumentor qJerry
[ class tree: qJerry ] [ index: qJerry ] [ all elements ]

Class: qJerry

Source Location: /qjerry.php

Class qJerry

Class Overview

Implements interfaces:

  • IteratorAggregate (internal interface)

qJerry: write less, do more. Now in PHP.

qJerry is the PHP class that provides a way to work with XML documents in jQuery-like style. It has methods for creating, modifying, querying XML documents and more. Generally speaking, qJerry is jQuery for server side.

qJerry has convenient API, similar to the jQuery's one, including naming and behavior of most methods. Almost all methods returns qJerry instance, so chaining is possible as well. People familiar with jQuery can start using qJerry immediately.

Example.

Say, we need to create the following XML document:

  1.    <?xml version="1.0" encoding="UTF-8"?>
  2.    <items><item id="1"/><item id="2"/></items>

Do it using traditional DOM functions:

  1.    $dom new DOMDocument('1.0''UTF-8');
  2.    $dom->appendChild($dom->createElement('items'));
  3.    $dom->documentElement->appendChild($dom->createElement('item'))->setAttribute('id''1');
  4.    $dom->documentElement->appendChild($dom->createElement('item'))->setAttribute('id''2');
  5.    echo $dom->saveXML();

The same using qJerry:

  1.    q('items')->append('item')->attr('id''1')->end()->append('item')->attr('id''2')->dump();

As can be seen, working with XML using qJerry is much easier than using DOM, even in most trivial case, never mind when it comes to complex manipulations with multiple queries and modifications of XML tree.

Creating qJerry instances.

There are three equivalent ways to create instance of the qJerry class:

  1.    $q new qJerry($content);        // using constructor
  2.    $q qJerry::create($content);    // using static method
  3.    $q q($content);                // using shortcut function q()

The last two calls can be chained with qJerry method calls.

See qJerry::__construct() for details.

The special case is the qJerry::fromArray() static method, that can be used to create XML from equivalent array structure:

  1.    $q qJerry::fromArray($_POST);

Querying XML documents.

qJerry uses XPath as query language, and unlike jQuery, it does not have any special selectors. There is simple no need to use them, since XPath is much more powerful and has good support in PHP out of the box.

Examples:

  1.    $q q('./users.xml');
  2.  
  3.    $items $q->find("/users/user[group='members' and not(@block = 'yes')]");
  4.    // or
  5.    $items $q->children("user")->filter("group='members'")->not("@block='yes'");

Iterating and looping.

qJerry implements IteratorAggregate interface, so it is possible to pass qJerry instance directly to foreach() statement. In such case elements of the matched set can be accessed inside foreach() loop as qJerry instances:

  1.    foreach($items as $item{
  2.      echo $item->attr('id').' - '.$item->children('login')->text()."\n";
  3.    }

It is also possible to iterate over the matched DOMElements:

  1.    foreach($items->get(as $elem{
  2.      echo $elem->getAttribute('id').' - '.$elem->getElementsByTagName('login')->item(0)->nodeValue."\n";
  3.    }

Error handling.

qJerry methods throws a qJException on error. There are few situations that cause an exception to be thrown:

  • file I/O errors
  • XML parsing errors
  • invalid arguments passed to the methods
  • array indexes out of bound
An empty or unchanged set can be returned by some methods. Make sure to check return values in your scripts.

Located in /qjerry.php [line 135]



		
				Author(s):
		
Information Tags:
Todo:  Some features to implement in future:
  • add support for attribute nodes
  • add support for namespaces
  • give more attention to text nodes
  • write automated tests

Properties

Methods

[ Top ]
Property Summary
DOMDocument   $document   Instance of current working DOM document.
string   $file   Filename of current working document.
boolean   $format   Whether format or not XML tree when saving.
integer   $length   Number of matched elements.
array   $nodes   Array of matched elements.
qJerry   $prev   Parent qJerry instance.
DOMXPath   $xp   DOMXPath instance for working DOM document.

[ Top ]
Method Summary
static qJerry   create()   Create new qJerry instance.
static qJerry   load()   Create qJerry object and load local XML file into it.
qJerry   __construct()   Constructor.
qJerry   add()   Add more elements, matched by the given expression, to the set of matched elements.
qJerry   after()   Insert content after each of the matched elements.
qJerry   andSelf()   Add the previous selection to the current selection.
qJerry   append()   Append content to the inside of every matched element.
qJerry   appendTo()   Append all of the matched elements to another, specified, set of elements.
string|false|qJerry   attr()   Access an attribute of the first matched element.
qJerry   before()   Insert content before each of the matched elements.
qJerry   children()   Get a set of elements containing all of the unique immediate children of each of the matched set of elements.
qJerry   clear()   Remove all child nodes from the set of matched elements.
qJerry   copy()   Clone matched DOM eslements and select the clones.
DOMDocument   doc()   Return current working DOM document.
qJerry   dump()   Dump the current working DOM document.
qJerry   each()   Execute a function within the context of every matched element.
qJerry   end()   Revert the most recent 'destructive' operation.
qJerry   eq()   Reduce the set of matched elements to a single element.
string|qJerry   file()   Get/set file name of the current working document.
qJerry   filter()   Filter the matched set using expression or callback function.
qJerry   find()   Search for all elements that match the specified expression.
qJerry   format()   Turn on/off formatting when saving the document.
qJerry   fromArray()   Create DOM document from the multi-dimensional array.
DOMElement|array   get()   Return a single element at a specified index.
ArrayIterator   getIterator()   IteratorAggregate interface implementation.
integer|false   index()   Return the index of the element.
qJerry   insertAfter()   Insert all of the matched elements after another, specified, set of elements.
qJerry   insertBefore()   Insert all of the matched elements before another, specified, set of elements.
boolean   is()   Test current selection against an expression.
string|false   name()   The tag name of first matched element.
qJerry   next()   Return the very next sibling for each element.
qJerry   nextAll()   Find all sibling elements after all the matched elements.
qJerry   not()   Remove elements matching the specified expression from the set of matched elements.
qJerry   parent()   Get a set of elements containing the unique parents of the matched set of elements.
qJerry   parents()   Get a set of elements containing the unique ancestors of the matched set of elements (except for the root element).
qJerry   prepend()   Prepend content to the inside of every matched element.
qJerry   prependTo()   Prepend all of the matched elements to another, specified, set of elements.
qJerry   prev()   Get a set of elements containing the unique previous siblings of each of the matched set of elements.
qJerry   prevAll()   Find all sibling elements before the current element.
qJerry   remove()   Removes all matched elements from the DOM document.
qJerry   removeAttr()   Remove an attribute from each of the matched elements.
qJerry   replaceAll()   Replaces the elements matched by the specified expression with the matched elements.
qJerry   replaceWith()   Replaces all matched elements with the specified HTML or DOM elements.
qJerry   reset()   Discard history of destructive operations.
qJerry   response()   Return current working document as server response.
qJerry   root()   Return qJerry instance initialized with the root element of the current working DOM document.
qJerry   save()   Save current working document to file.
string   saveXML()   Create string representation of the current working document.
qJerry   siblings()   Get a set of elements containing all of the unique siblings of each of the matched set of elements.
integer   size()   The number of elements in the qJerry object.
qJerry   slice()   Select a subset of the matched elements.
string|qJerry   text()   Get/set the text contents of all matched elements.
qJerry   wrap()   Wrap all matched elements with a structure of other elements.
qJerry   wrapAll()   Wrap all the elements in the matched set into a single wrapper element.
qJerry   wrapInner()   Wrap the inner child contents of each matched element (including text nodes) with an HTML structure.

[ Top ]
Properties
DOMDocument   $document = null [line 140]

Instance of current working DOM document.

API Tags:
Access:  protected


[ Top ]
string   $file = '' [line 170]

Filename of current working document.

API Tags:
Access:  public


[ Top ]
boolean   $format = false [line 164]

Whether format or not XML tree when saving.

API Tags:
Access:  protected


[ Top ]
integer   $length = 0 [line 176]

Number of matched elements.

API Tags:
Access:  public


[ Top ]
array   $nodes = array() [line 146]

Array of matched elements.

API Tags:
Access:  protected


[ Top ]
qJerry   $prev = null [line 152]

Parent qJerry instance.

API Tags:
Access:  protected


[ Top ]
DOMXPath   $xp = null [line 158]

DOMXPath instance for working DOM document.

API Tags:
Access:  protected


[ Top ]
Methods
static method create  [line 348]

  static qJerry create( [mixed $content = null]  )

Create new qJerry instance.

This method is just a wrapper for 'new qJerry(...)' call.

Parameters:
mixed   $content:  Data with which qJerry object will be initialized.

API Tags:
Return:  New instance.
Access:  public


[ Top ]
static method load  [line 367]

  static qJerry load( string $file  )

Create qJerry object and load local XML file into it.

Example: load file 'somefile.xml' from current directory.

  1.    $q qJerry::load('somefile.xml');

Parameters:
string   $file:  File name to load.

API Tags:
Return:  New instance.
Access:  public


[ Top ]
Constructor __construct  [line 236]

  qJerry __construct( [string|DOMDocument|DOMElement|DOMNodeList|null $content = null], [qJerry $parent = null]  )

Constructor.

The constructor is used to create and initialize a new qJerry object instance with passed data. The $content parameter can be a value of several types.

If the $content argument is a string and it starts with "&lt;?xml", then try to load an XML document from it, or throw qJException on failure:

  1.    $xml = '<?xml version="1.0" encoding="UTF-8"?>'."\n".
  2.           '<items><item id="1"/><item id="2"/></items>';
  3.  
  4.    $q = new qJerry($xml);

Else, if string matches pattern "/^[a-z_][0-9a-z\-\._]*$/i", create new DOM document with the root element with specified name (useful for creating XML documents from scratch):

  1.    $q new qJerry('root-element');

Otherwise, treat string as file name or URL and try to load it (with transparent support for URL wrappers), or throw qJException on failure:

  1.    $q new qJerry('./filename.xml');
  2.    $q new qJerry('http://qjerry.com/example.xml');

If $content is the DOMDocument, then load it and set its root element as the only member of the matched set:

  1.    $dom new DOMDocument('1.0''UTF-8');
  2.    $dom->appendChild($dom->createElement('root'));
  3.    $dom->documentElement->setAttribute('name''Root element');
  4.  
  5.    $q new qJerry($dom);

If $content is the DOMElement, then load DOM document to which specified element belongs, and set this element as the only member of the matched set:

  1.    $q new qJerry($dom->documentElement);

If $content is the DOMNodeList, then convert node list to array and set it as the matched set:

  1.    $q new qJerry($dom->getElementsByTagName('root'));

If $content is not specified, then create an empty document (userful for creating XML documents from scratch):

  1.    $q new qJerry();
12

If $content is of any other type, then throw a qJException.

Parameters:
string|DOMDocument|DOMElement|DOMNodeList|null   $content:  Data with which qJerry object will be initialized.
qJerry   $parent:  Optional parent qJerry object. For internal use only.

API Tags:
Access:  public


[ Top ]
add  [line 993]

  qJerry add( [string $expr = null]  )

Add more elements, matched by the given expression, to the set of matched elements.

Parameters:
string   $expr: 

API Tags:
Access:  public


[ Top ]
after  [line 1575]

  qJerry after( string|qJerry|DOMDocument|DOMElement|DOMNodeList $content  )

Insert content after each of the matched elements.

Parameters:
string|qJerry|DOMDocument|DOMElement|DOMNodeList   $content:  Content to be inserted.

API Tags:
Return:  The set of the inserted elements.
Access:  public


[ Top ]
andSelf  [line 1263]

  qJerry andSelf( )

Add the previous selection to the current selection.

Useful for traversing elements, and then adding something that was matched before the last traversion.


API Tags:
Access:  public


[ Top ]
append  [line 1431]

  qJerry append( string|qJerry|DOMDocument|DOMElement|DOMNodeList $content, [string $ns = '']  )

Append content to the inside of every matched element.

This operation is similar to calling appendChild on all of the specified elements, adding them into the document. Optional namespace for the appended element may be provided.

Parameters:
string|qJerry|DOMDocument|DOMElement|DOMNodeList   $content:  Content to be appended.
string   $ns:  Optional namespace for appended element.

API Tags:
Access:  public


[ Top ]
appendTo  [line 1487]

  qJerry appendTo( qJerry|DOMDocument|DOMElement|DOMNodeList $content  )

Append all of the matched elements to another, specified, set of elements.

This operation is, essentially, the reverse of doing a regular $(A).append(B), in that instead of appending B to A, you're appending A to B.

Parameters:
qJerry|DOMDocument|DOMElement|DOMNodeList   $content: 

API Tags:
Access:  public

Information Tags:
Todo:  Text selectors.

[ Top ]
attr  [line 778]

  string|false|qJerry attr( [string $name = null], [string $value = null], [array $properties = null], callback $callback  )

Access an attribute of the first matched element.

Set or get values of single or multiple attributes, on all matched elements.

Parameters:
string   $name:  The name of the attribute to set/get.
string   $value:  The value to set the attribute to.
array   $properties:  Array of key=>value pairs.
callback   $callback: 

API Tags:
Access:  public


[ Top ]
before  [line 1609]

  qJerry before( mixed $content  )

Insert content before each of the matched elements.

Parameters:
mixed   $content:  Content to be inserted.

API Tags:
Return:  The set of the inserted elements.
Access:  public


[ Top ]
children  [line 1015]

  qJerry children( [string $expr = null]  )

Get a set of elements containing all of the unique immediate children of each of the matched set of elements.

This set can be filtered with an optional expression that will cause only elements matching the expression to be collected. Also note: while parents() will look at all ancestors, children() will only consider immediate child elements.

Parameters:
string   $expr:  An expression with which to filter the result set.

API Tags:
Access:  public


[ Top ]
clear  [line 1936]

  qJerry clear( )

Remove all child nodes from the set of matched elements.

This method is synonym of jQuery's empty() method, since 'empty' is reserved word in PHP.


API Tags:
Access:  public


[ Top ]
copy  [line 1978]

  qJerry copy( )

Clone matched DOM eslements and select the clones.

This method is synonym of jQuery's clone() method, since the word 'clone' is reserved in PHP.


API Tags:
Return:  A set of copied (cloned) elements.
Access:  public


[ Top ]
doc  [line 653]

  DOMDocument doc( )

Return current working DOM document.


API Tags:
Return:  Current working DOM document.
Access:  public


[ Top ]
dump  [line 621]

  qJerry dump( )

Dump the current working DOM document.


API Tags:
Access:  public


[ Top ]
each  [line 691]

  qJerry each( callback $callback  )

Execute a function within the context of every matched element.

Every time the callback function is executed the 1st argument points to the qJerry object of specific DOMElement, and the 2nd argument represents the index of that element in the matched set.

Returning 'false' from within the callback function completely stops the loop through all of the elements (this is like using a 'break' with a normal loop). Returning 'true' from within the loop skips to the next iteration (this is like using a 'continue' with a normal loop).

Parameters:
callback   $callback:  Callback function name.

API Tags:
Access:  public


[ Top ]
end  [line 1290]

  qJerry end( )

Revert the most recent 'destructive' operation.

Change the set of matched elements to its previous state, right before the destructive operation. If there was no destructive operation before, current set is returned.

Note: jQuery's version of this method returns an empty set if there was no destructive operation before.


API Tags:
Access:  public


[ Top ]
eq  [line 709]

  qJerry eq( [integer $index = 0]  )

Reduce the set of matched elements to a single element.

If no $index specified, then the set will be reduced to the very first element.

Parameters:
integer   $index:  Index of the element.

API Tags:
Access:  public


[ Top ]
file  [line 574]

  string|qJerry file( [string|null $file = null]  )

Get/set file name of the current working document.

Parameters:
string|null   $file: 

API Tags:
Access:  public


[ Top ]
filter  [line 868]

  qJerry filter( [string|callback $expr = null]  )

Filter the matched set using expression or callback function.

Remove all elements from the set of matched elements that do not match the specified expression or function.

Parameters:
string|callback   $expr:  An expression or function to pass to the filter.

API Tags:
Access:  public


[ Top ]
find  [line 1041]

  qJerry find( [string $expr = null]  )

Search for all elements that match the specified expression.

Important note: although the expression is tested in context of each matched element, the resulting set may contain elements from any place of the document, depending on XPath passed as an expression.

Parameters:
string   $expr:  An expression with which to find.

API Tags:
Access:  public


[ Top ]
format  [line 551]

  qJerry format( [boolean $format = true]  )

Turn on/off formatting when saving the document.

Parameters:
boolean   $format: 

API Tags:
Access:  public


[ Top ]
fromArray  [line 444]

  qJerry fromArray( array $array, [string $name = null], [mixed $value = null], [qJerry $node = null]  )

Create DOM document from the multi-dimensional array.

Value returned by this method highly depends on correct structure of input array. There are the basic rules:

  • one array key corresponds to one DOM element
  • attribute name should begin with '@' character
  • value of an attribute should be of scalar type
  • elements with the same name on the same level should end with suffix '~1', '~2', ...

This method is useful for processing HTML forms. In such case, the 'name' attribute of each input element of the form should follow the syntax of HTML array feature.

Example form:

  1.  <form action="user.php" method="post">
  2.    <input type="hidden" name="user[@id]" value="100"/>
  3.    <input type="checkbox" name="user[@block]" value="no" checked="checked"/>
  4.    <input type="text" name="user[login]" value="myUserName"/>
  5.    <input type="password" name="user[password]" value="somePassword"/>
  6.    <input type="text" name="user[group~1]" value="members"/>
  7.    <input type="text" name="user[group~2]" value="bloggers"/>
  8.    <input type="text" name="user[group~3]" value="admins"/>
  9.    <input type="submit"/>
  10.  </form>

Example form handler:

  1.  <?php
  2.    print_r($_POST);
  3.  
  4.    $q qJerry::fromArray($_POST'user');
  5.  
  6.    $q->format()->dump();
  7.  ?>

This will output:

  1.    Array
  2.    (
  3.        [user] => Array
  4.            (
  5.                [@id] => 100
  6.                [@block] = no
  7.                [login] => myUserName
  8.                [password] => somePassword
  9.                [group~1] => members
  10.                [group~2] => bloggers
  11.                [group~3] => admins
  12.            )
  13.    )
  14.    <?xml version="1.0" encoding="UTF-8"?>
  15.    <user id="100" block="no">
  16.      <login>myUserName</login>
  17.      <password>somePassword</password>
  18.      <group>members</group>
  19.      <group>bloggers</group>
  20.      <group>admins</group>
  21.    </user>

Parameters:
array   $array:  Input array.
string   $name:  The key from which to start.
mixed   $value:  Value. Internal use only.
qJerry   $node:  Current node. Internal use only.


[ Top ]
get  [line 725]

  DOMElement|array get( [integer $index = null]  )

Return a single element at a specified index.

If no $index specified, then whole array will be returned.

Parameters:
integer   $index:  Index of the element.

API Tags:
Access:  public


[ Top ]
getIterator  [line 326]

  ArrayIterator getIterator( )

IteratorAggregate interface implementation.

There is no need to call this method directly. It allows to iterate over the matched set using foreach() loop, just like over an array of qJerry instances.

  1.    foreach($q as $item)
  2.      echo $item->attr('id')."\n";


API Tags:
Access:  public


Implementation of:
IteratorAggregate::getIterator

[ Top ]
index  [line 744]

  integer|false index( DOMElement $element  )

Return the index of the element.

If no such element found in the matched set, then return false.

Parameters:
DOMElement   $element:  Element, which index need to be found.

API Tags:
Access:  public


[ Top ]
insertAfter  [line 1646]

  qJerry insertAfter( mixed $content  )

Insert all of the matched elements after another, specified, set of elements.

This operation is, essentially, the reverse of doing a regular q(A)->after(B), in that instead of inserting B after A, you're inserting A after B.

Parameters:
mixed   $content:  Content to be inserted.

API Tags:
Return:  The set of the inserted elements.
Access:  public


[ Top ]
insertBefore  [line 1669]

  qJerry insertBefore( mixed $content  )

Insert all of the matched elements before another, specified, set of elements.

This operation is, essentially, the reverse of doing a regular q(A).before(B), in that instead of inserting B before A, you're inserting A before B.

Parameters:
mixed   $content:  Content to be inserted.

API Tags:
Return:  The set of the inserted elements.
Access:  public


[ Top ]
is  [line 908]

  boolean is( [string $expr = null]  )

Test current selection against an expression.

Checks the current selection against an expression and returns true, if at least one element of the selection fits the given expression.

Parameters:
string   $expr:  The expression with which to filter.

API Tags:
Access:  public


[ Top ]
name  [line 673]

  string|false name( )

The tag name of first matched element.


API Tags:
Access:  public


[ Top ]
next  [line 1062]

  qJerry next( [string $expr = null]  )

Return the very next sibling for each element.

An optional expression to filter the result may be provided.

Parameters:
string   $expr:  An expression to filter the returned set.

API Tags:
Access:  public


[ Top ]
nextAll  [line 1088]

  qJerry nextAll( [string $expr = null]  )

Find all sibling elements after all the matched elements.

Optional expression to filter the matched set may be used.

Parameters:
string   $expr:  An expression with which to filter the result.

API Tags:
Access:  public


[ Top ]
not  [line 926]

  qJerry not( [string|array|DOMElement $expr = null]  )

Remove elements matching the specified expression from the set of matched elements.

Parameters:
string|array|DOMElement   $expr:  An expression with which to remove matching elements.

API Tags:
Access:  public


[ Top ]
parent  [line 1114]

  qJerry parent( [string $expr = null]  )

Get a set of elements containing the unique parents of the matched set of elements.

Optional expression to filter the matched set may be used.

Parameters:
string   $expr:  An expression with which to filter the result.

API Tags:
Access:  public


[ Top ]
parents  [line 1137]

  qJerry parents( [string $expr = null]  )

Get a set of elements containing the unique ancestors of the matched set of elements (except for the root element).

Parameters:
string   $expr:  An expression with which to filter the result.

API Tags:
Access:  public

Information Tags:
Todo:  Make sure that exception for the root element applied.

[ Top ]
prepend  [line 1509]

  qJerry prepend( string|qJerry|DOMDocument|DOMElement|DOMNodeList $content, [ $ns = null]  )

Prepend content to the inside of every matched element.

This operation is the best way to insert elements inside, at the beginning, of all matched elements.

Parameters:
string|qJerry|DOMDocument|DOMElement|DOMNodeList   $content:  Content to be prepended.
   $ns: 

API Tags:
Access:  public


[ Top ]
prependTo  [line 1552]

  qJerry prependTo( qJerry|DOMDocument|DOMElement|DOMNodeList $content  )

Prepend all of the matched elements to another, specified, set of elements.

This operation is, essentially, the reverse of doing a regular q(A).prepend(B), in that instead of prepending B to A, you're prepending A to B.

Parameters:
qJerry|DOMDocument|DOMElement|DOMNodeList   $content:  An element set to prepend to.

API Tags:
Access:  public


[ Top ]
prev  [line 1162]

  qJerry prev( [string $expr = null]  )

Get a set of elements containing the unique previous siblings of each of the matched set of elements.

An optional expression to filter the result may be provided.

Parameters:
string   $expr:  An expression to filter the returned set.

API Tags:
Access:  public


[ Top ]
prevAll  [line 1188]

  qJerry prevAll( [string $expr = null]  )

Find all sibling elements before the current element.

An optional expression to filter the result may be provided.

Parameters:
string   $expr:  An expression to filter the returned set.

API Tags:
Access:  public


[ Top ]
remove  [line 1957]

  qJerry remove( [string $expr = null]  )

Removes all matched elements from the DOM document.

Parameters:
string   $expr:  An expression to filter the matched set.

API Tags:
Return:  A set of removed elements.
Access:  public


[ Top ]
removeAttr  [line 847]

  qJerry removeAttr( string $name  )

Remove an attribute from each of the matched elements.

Parameters:
string   $name:  The name of the attribute to remove.

API Tags:
Access:  public


[ Top ]
replaceAll  [line 1887]

  qJerry replaceAll( [string $expr = null]  )

Replaces the elements matched by the specified expression with the matched elements.

This function is the complement to replaceWith() which does the same task with the parameters reversed.

Parameters:
string   $expr: 

API Tags:
Access:  public


[ Top ]
replaceWith  [line 1903]

  qJerry replaceWith( string|DOMDocument|DOMElement|DOMNodeList $elem  )

Replaces all matched elements with the specified HTML or DOM elements.

Parameters:
string|DOMDocument|DOMElement|DOMNodeList   $elem: 

API Tags:
Access:  public


[ Top ]
reset  [line 1300]

  qJerry reset( )

Discard history of destructive operations.


API Tags:
Access:  public


[ Top ]
response  [line 635]

  qJerry response( )

Return current working document as server response.

This method is useful when writing AJAX enabled applications.


API Tags:
Access:  public


[ Top ]
root  [line 663]

  qJerry root( )

Return qJerry instance initialized with the root element of the current working DOM document.


API Tags:
Access:  public


[ Top ]
save  [line 590]

  qJerry save( [string $file = '']  )

Save current working document to file.

Parameters:
string   $file:  File name to which to save the document.

API Tags:
Access:  public


[ Top ]
saveXML  [line 611]

  string saveXML( )

Create string representation of the current working document.


API Tags:
Access:  public


[ Top ]
siblings  [line 1213]

  qJerry siblings( [string $expr = null]  )

Get a set of elements containing all of the unique siblings of each of the matched set of elements.

Can be filtered with an optional expression.

Parameters:
string   $expr:  An expression to filter the returned set.

API Tags:
Access:  public


[ Top ]
size  [line 758]

  integer size( )

The number of elements in the qJerry object.


API Tags:
Return:  Number of elements in the matched set.
Access:  public


[ Top ]
slice  [line 982]

  qJerry slice( integer $offset, integer $length  )

Select a subset of the matched elements.

Attention: this is a PHP-style version of jQuery's slice() method. It relies on array_slice() function and inherits its behavior.

Parameters:
integer   $offset: 
integer   $length: 

API Tags:
Access:  public


[ Top ]
text  [line 1320]

  string|qJerry text( [string $text = null]  )

Get/set the text contents of all matched elements.

Set the text contents of all matched elements to specified value. If there was no value specified, the combined text contents of all matched elements is returned.

Note: after setting text values, qJerry object with the same set of the elements is returned.

Parameters:
string   $text:  The text to which to set matched elements.

API Tags:
Access:  public


[ Top ]
wrap  [line 1739]

  qJerry wrap( string|qJerry|DOMDocument|DOMElement|DOMNodeList $elem  )

Wrap all matched elements with a structure of other elements.

Parameters:
string|qJerry|DOMDocument|DOMElement|DOMNodeList   $elem:  The element name or the DOM tree to wrap elements with.

API Tags:
Return:  The root element of the wrapping structure.
Access:  public


[ Top ]
wrapAll  [line 1782]

  qJerry wrapAll( string|qJerry|DOMDocument|DOMElement|DOMNodeList $elem  )

Wrap all the elements in the matched set into a single wrapper element.

This is different from wrap() method where each element in the matched set would get wrapped with an element.

Parameters:
string|qJerry|DOMDocument|DOMElement|DOMNodeList   $elem:  The element name or the DOM tree to wrap elements with.

API Tags:
Return:  The root element of the wrapping structure.
Access:  public


[ Top ]
wrapInner  [line 1833]

  qJerry wrapInner( string|qJerry|DOMDocument|DOMElement|DOMNodeList $elem  )

Wrap the inner child contents of each matched element (including text nodes) with an HTML structure.

Parameters:
string|qJerry|DOMDocument|DOMElement|DOMNodeList   $elem:  The element name or the DOM tree to wrap elements with.

API Tags:
Access:  public


[ Top ]

Documentation generated on Wed, 04 Mar 2009 14:09:12 +0300 by phpDocumentor 1.4.1