|
QueryPath
2.1.1
|
The Query Path object is the primary tool in this library. More...
Public Member Functions | |
| __construct ($document=NULL, $string=NULL, $options=array()) | |
| Constructor. | |
| getOptions () | |
| Get the effective options for the current QueryPath object. | |
| top ($selector=NULL) | |
| Select the root element of the document. | |
| find ($selector) | |
| Given a CSS Selector, find matching items. | |
| xpath ($query, $options=array()) | |
| Execute an XPath query and store the results in the QueryPath. | |
| size () | |
| Get the number of elements currently wrapped by this object. | |
| count () | |
| Get the number of elements currently wrapped by this object. | |
| get ($index=NULL, $asObject=FALSE) | |
| Get one or all elements from this object. | |
| document () | |
| Get the DOMDocument that we currently work with. | |
| xinclude () | |
| On an XML document, load all XIncludes. | |
| toArray () | |
| Get all current elements wrapped in an array. | |
| attr ($name=NULL, $value=NULL) | |
| Get/set an attribute. | |
| hasAttr ($attrName) | |
| Check to see if the given attribute is present. | |
| css ($name=NULL, $value= '') | |
| Set/get a CSS value for the current element(s). | |
| dataURL ($attr, $data=NULL, $mime= 'application/octet-stream', $context=NULL) | |
| Insert or retrieve a Data URL. | |
| removeAttr ($name) | |
| Remove the named attribute from all elements in the current QueryPath. | |
| eq ($index) | |
| Reduce the matched set to just one. | |
| is ($selector) | |
| Given a selector, this checks to see if the current set has one or more matches. | |
| filter ($selector) | |
| Filter a list down to only elements that match the selector. | |
| filterLambda ($fn) | |
| Filter based on a lambda function. | |
| filterPreg ($regex) | |
| Use regular expressions to filter based on the text content of matched elements. | |
| filterCallback ($callback) | |
| Filter based on a callback function. | |
| not ($selector) | |
| Filter a list to contain only items that do NOT match. | |
| index ($subject) | |
| Get an item's index. | |
| map ($callback) | |
| Run a function on each item in a set. | |
| slice ($start, $length=0) | |
| Narrow the items in this object down to only a slice of the starting items. | |
| each ($callback) | |
| Run a callback on each item in the list of items. | |
| eachLambda ($lambda) | |
| An each() iterator that takes a lambda function. | |
| append ($data) | |
| Insert the given markup as the last child. | |
| appendTo (QueryPath $dest) | |
| Append the current elements to the destination passed into the function. | |
| prepend ($data) | |
| Insert the given markup as the first child. | |
| prependTo (QueryPath $dest) | |
| Take all nodes in the current object and prepend them to the children nodes of each matched node in the passed-in QueryPath object. | |
| before ($data) | |
| Insert the given data before each element in the current set of matches. | |
| insertBefore (QueryPath $dest) | |
| Insert the current elements into the destination document. | |
| insertAfter (QueryPath $dest) | |
| Insert the contents of the current QueryPath after the nodes in the destination QueryPath object. | |
| after ($data) | |
| Insert the given data after each element in the current QueryPath object. | |
| replaceWith ($new) | |
| Replace the existing element(s) in the list with a new one. | |
| unwrap () | |
| Remove the parent element from the selected node or nodes. | |
| wrap ($markup) | |
| Wrap each element inside of the given markup. | |
| wrapAll ($markup) | |
| Wrap all elements inside of the given markup. | |
| wrapInner ($markup) | |
| Wrap the child elements of each item in the list with the given markup. | |
| deepest () | |
| Reduce the set of matches to the deepest child node in the tree. | |
| tag () | |
| The tag name of the first element in the list. | |
| remove ($selector=NULL) | |
| Remove any items from the list if they match the selector. | |
| replaceAll ($selector, DOMDocument $document) | |
| This replaces everything that matches the selector with the first value in the current list. | |
| add ($selector) | |
| Add more elements to the current set of matches. | |
| end () | |
| Revert to the previous set of matches. | |
| andSelf () | |
| Combine the current and previous set of matched objects. | |
| removeChildren () | |
| Remove all child nodes. | |
| children ($selector=NULL) | |
| Get the children of the elements in the QueryPath object. | |
| contents () | |
| Get all child nodes (not just elements) of all items in the matched set. | |
| siblings ($selector=NULL) | |
| Get a list of siblings for elements currently wrapped by this object. | |
| closest ($selector) | |
| Find the closest element matching the selector. | |
| parent ($selector=NULL) | |
| Get the immediate parent of each element in the QueryPath. | |
| parents ($selector=NULL) | |
| Get all ancestors of each element in the QueryPath. | |
| html ($markup=NULL) | |
| Set or get the markup for an element. | |
| innerHTML () | |
| Fetch the HTML contents INSIDE of the first QueryPath item. | |
| innerXHTML () | |
| Fetch child (inner) nodes of the first match. | |
| innerXML () | |
| Fetch child (inner) nodes of the first match. | |
| textImplode ($sep= ', ', $filterEmpties=TRUE) | |
| Retrieve the text of each match and concatenate them with the given separator. | |
| childrenText ($separator= ' ') | |
| Get the text contents from just child elements. | |
| text ($text=NULL) | |
| Get or set the text contents of a node. | |
| textBefore ($text=NULL) | |
| Get or set the text before each selected item. | |
| textAfter ($text=NULL) | |
| val ($value=NULL) | |
| Set or get the value of an element's 'value' attribute. | |
| xhtml ($markup=NULL) | |
| Set or get XHTML markup for an element or elements. | |
| xml ($markup=NULL) | |
| Set or get the XML markup for an element or elements. | |
| writeXML ($path=NULL, $options=NULL) | |
| Send the XML document to the client. | |
| writeHTML ($path=NULL) | |
| Writes HTML to output. | |
| writeXHTML ($path=NULL) | |
| Write an XHTML file to output. | |
| next ($selector=NULL) | |
| Get the next sibling of each element in the QueryPath. | |
| nextAll ($selector=NULL) | |
| Get all siblings after an element. | |
| prev ($selector=NULL) | |
| Get the next sibling before each element in the QueryPath. | |
| prevAll ($selector=NULL) | |
| Get the previous siblings for each element in the QueryPath. | |
| peers ($selector=NULL) | |
| addClass ($class) | |
| Add a class to all elements in the current QueryPath. | |
| removeClass ($class) | |
| Remove the named class from any element in the QueryPath that has it. | |
| hasClass ($class) | |
| Returns TRUE if any of the elements in the QueryPath have the specified class. | |
| branch ($selector=NULL) | |
| Branch the base QueryPath into another one with the same matches. | |
| cloneAll () | |
| Perform a deep clone of each node in the QueryPath. | |
| __clone () | |
| Clone the QueryPath. | |
| detach ($selector=NULL) | |
| Detach any items from the list if they match the selector. | |
| attach (QueryPath $dest) | |
| Attach any items from the list if they match the selector. | |
| has ($contained) | |
| Reduce the elements matched by QueryPath to only those which contain the given item. | |
| emptyElement () | |
| Empty everything within the specified element. | |
| even () | |
| Get the even elements, so counter-intuitively 1, 3, 5, etc. | |
| odd () | |
| Get the odd elements, so counter-intuitively 0, 2, 4, etc. | |
| first () | |
| Get the first matching element. | |
| firstChild () | |
| Get the first child of the matching element. | |
| last () | |
| Get the last matching element. | |
| lastChild () | |
| Get the last child of the matching element. | |
| nextUntil ($selector=NULL) | |
| Get all siblings after an element until the selector is reached. | |
| prevUntil ($selector=NULL) | |
| Get the previous siblings for each element in the QueryPath until the selector is reached. | |
| parentsUntil ($selector=NULL) | |
| Get all ancestors of each element in the QueryPath until the selector is reached. | |
| setMatches ($matches, $unique=TRUE) | |
| EXPERT: Be very, very careful using this. | |
| __call ($name, $arguments) | |
| Call extension methods. | |
| getIterator () | |
| Dynamically generate certain properties. | |
Static Public Member Functions | |
| static | encodeDataURL ($data, $mime= 'application/octet-stream', $context=NULL) |
| A static function for transforming data into a Data URL. | |
Public Attributes | |
| const | VERSION = '2.1.1' |
| The version string for this version of QueryPath. | |
| const | HTML_STUB |
| This is a stub HTML 4.01 document. | |
| const | XHTML_STUB |
| This is a stub XHTML document. | |
| const | DEFAULT_PARSER_FLAGS = NULL |
| Default parser flags. | |
| const | JS_CSS_ESCAPE_CDATA = '\\1' |
| const | JS_CSS_ESCAPE_CDATA_CCOMMENT = '/* \\1 */' |
| const | JS_CSS_ESCAPE_CDATA_DOUBLESLASH = '// \\1' |
| const | JS_CSS_ESCAPE_NONE = '' |
| $length = 0 | |
| The number of current matches. | |
Protected Member Functions | |
| deepestNode (DOMNode $ele, $depth=0, $current=NULL, &$deepest=NULL) | |
| A depth-checking function. | |
| prepareInsert ($item) | |
| Prepare an item for insertion into a DOM. | |
| isXMLish ($string) | |
| Determine whether a given string looks like XML or not. | |
Protected Attributes | |
| $document = NULL | |
| The base DOMDocument. | |
| $matches = array() | |
| The array of matches. | |
| $last = array() | |
| The last array of matches. | |
The Query Path object is the primary tool in this library.
To create a new Query Path, use the qp() function.
If you are new to these documents, start at the QueryPath.php page. There you will find a quick guide to the tools contained in this project.
A note on serialization: QueryPath uses DOM classes internally, and those do not serialize well at all. In addition, QueryPath may contain many extensions, and there is no guarantee that extensions can serialize. The moral of the story: Don't serialize QueryPath.
| __construct | ( | $ | document = NULL, |
| $ | string = NULL, |
||
| $ | options = array() |
||
| ) |
Constructor.
This should not be called directly. Use the qp() factory function instead.
| mixed | $document | A document-like object. |
| string | $string | A CSS 3 Selector |
| array | $options | An associative array of options. |
Definition at line 396 of file QueryPath.php.
References get(), DEFAULT_PARSER_FLAGS, $document, document(), setMatches(), isXMLish(), and find().
| __call | ( | $ | name, |
| $ | arguments | ||
| ) |
Call extension methods.
This function is used to invoke extension methods. It searches the registered extenstensions for a matching function name. If one is found, it is executed with the arguments in the $arguments array.
| QueryPathException | An exception is thrown if a non-existent method is called. |
Definition at line 4164 of file QueryPath.php.
References QueryPathExtensionRegistry\$useRegistry, QueryPathExtensionRegistry\getExtensions(), QueryPathExtensionRegistry\hasMethod(), and QueryPathExtensionRegistry\getMethodClass().
| __clone | ( | ) |
Clone the QueryPath.
This makes a deep clone of the elements inside of the QueryPath.
This clones only the QueryPathImpl, not all of the decorators. The clone operator in PHP should handle the cloning of the decorators.
Definition at line 3439 of file QueryPath.php.
References cloneAll().
| add | ( | $ | selector | ) |
Add more elements to the current set of matches.
This begins the new query at the top of the DOM again. The results found when running this selector are then merged into the existing results. In this way, you can add additional elements to the existing set.
| string | $selector | A valid selector. |
Definition at line 2181 of file QueryPath.php.
References last(), qp(), document(), and $selector.
| addClass | ( | $ | class | ) |
Add a class to all elements in the current QueryPath.
This searchers for a class attribute on each item wrapped by the current QueryPath object. If no attribute is found, a new one is added and its value is set to $class. If a class attribute is found, then the value is appended on to the end.
| string | $class | The name of the class. |
Definition at line 3257 of file QueryPath.php.
| after | ( | $ | data | ) |
Insert the given data after each element in the current QueryPath object.
This inserts the element as a peer to the currently matched elements. Contrast this with append(), which inserts the data as children of matched elements.
| mixed | $data | The data to be appended. |
| QueryPathException | Thrown if $data is an unsupported object type. |
Definition at line 1707 of file QueryPath.php.
References $data, and prepareInsert().
Referenced by insertAfter(), and textAfter().
| andSelf | ( | ) |
Combine the current and previous set of matched objects.
Example:
The code above will contain a list of all p elements and all div elements that are beneath p elements.
Definition at line 2248 of file QueryPath.php.
| append | ( | $ | data | ) |
Insert the given markup as the last child.
The markup will be inserted into each match in the set.
The same element cannot be inserted multiple times into a document. DOM documents do not allow a single object to be inserted multiple times into the DOM. To insert the same XML repeatedly, we must first clone the object. This has one practical implication: Once you have inserted an element into the object, you cannot further manipulate the original element and expect the changes to be replciated in the appended object. (They are not the same -- there is no shared reference.) Instead, you will need to retrieve the appended object and operate on that.
| mixed | $data | This can be either a string (the usual case), or a DOM Element. |
| QueryPathException | Thrown if $data is an unsupported object type. |
Definition at line 1520 of file QueryPath.php.
References $data, prepareInsert(), document(), and setMatches().
Referenced by appendTo(), html(), xml(), and attach().
| appendTo | ( | QueryPath $ | dest | ) |
Append the current elements to the destination passed into the function.
This cycles through all of the current matches and appends them to the context given in $destination. If a selector is provided then the $destination is queried (using that selector) prior to the data being appended. The data is then appended to the found items.
| QueryPathException | Thrown if $data is an unsupported object type. |
Definition at line 1569 of file QueryPath.php.
References append().
| attach | ( | QueryPath $ | dest | ) |
Attach any items from the list if they match the selector.
If no selector is specified, this will remove all current matches from the document.
Definition at line 3498 of file QueryPath.php.
| attr | ( | $ | name = NULL, |
| $ | value = NULL |
||
| ) |
Get/set an attribute.
When an attribute value is retrieved, only the attribute value of the FIRST match is returned.
| mixed | $name | The name of the attribute or an associative array of name/value pairs. |
| string | $value | A value (used only when setting an individual property). |
Definition at line 842 of file QueryPath.php.
| before | ( | $ | data | ) |
Insert the given data before each element in the current set of matches.
This will take the give data (XML or HTML) and put it before each of the items that the QueryPath object currently contains. Contrast this with after().
| mixed | $data | The data to be inserted. This can be XML in a string, a DomFragment, a DOMElement, or the other usual suspects. (See qp()). |
| QueryPathException | Thrown if $data is an unsupported object type. |
Definition at line 1644 of file QueryPath.php.
References $data, and prepareInsert().
Referenced by insertBefore(), and textBefore().
| branch | ( | $ | selector = NULL | ) |
Branch the base QueryPath into another one with the same matches.
This function makes a copy of the QueryPath object, but keeps the new copy (initially) pointed at the same matches. This object can then be queried without changing the original QueryPath. However, changes to the elements inside of this QueryPath will show up in the QueryPath from which it is branched.
Compare this operation with cloneAll(). The cloneAll() call takes the current QueryPath object and makes a copy of all of its matches. You continue to operate on the same QueryPath object, but the elements inside of the QueryPath are copies of those before the call to cloneAll().
This, on the other hand, copies the QueryPath, but keeps valid references to the document and the wrapped elements. A new query branch is created, but any changes will be written back to the same document.
In practice, this comes in handy when you want to do multiple queries on a part of the document, but then return to a previous set of matches. (see QPTPL for examples of this in practice).
Example:
<?php $qp = qp(QueryPath::HTML_STUB); $branch = $qp->branch(); $branch->find('title')->text('Title'); $qp->find('body')->text('This is the body')->writeHTML; ?>
Notice that in the code, each of the QueryPath objects is doing its own query. However, both are modifying the same document. The result of the above would look something like this:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"></meta> <title>Title</title> </head> <body>This is the body</body> </html>
Notice that while $qp and $banch were performing separate queries, they both modified the same document.
In jQuery or a browser-based solution, you generally do not need a branching function because there is (implicitly) only one document. In QueryPath, there is no implicit document. Every document must be explicitly specified (and, in most cases, parsed -- which is costly). Branching makes it possible to work on one document with multiple QueryPath objects.
| string | $selector | If a selector is passed in, an additional find() will be executed on the branch before it is returned. (Added in QueryPath 2.0.) |
Definition at line 3405 of file QueryPath.php.
References qp(), and $selector.
Referenced by childrenText(), and has().
| children | ( | $ | selector = NULL | ) |
Get the children of the elements in the QueryPath object.
If a selector is provided, the list of children will be filtered through the selector.
| string | $selector | A valid selector. |
Definition at line 2293 of file QueryPath.php.
References $c, $selector, setMatches(), and filter().
| childrenText | ( | $ | separator = ' ' | ) |
Get the text contents from just child elements.
This is a specialized variant of textImplode() that implodes text for just the child elements of the current element.
| string | $separator | The separator that will be inserted between found text content. |
Definition at line 2702 of file QueryPath.php.
References branch().
| cloneAll | ( | ) |
Perform a deep clone of each node in the QueryPath.
This does not clone the QueryPath object, but instead clones the list of nodes wrapped by the QueryPath. Every element is deeply cloned.
This method is analogous to jQuery's clone() method.
This is a destructive operation, which means that end() will revert the list back to the clone's original.
Definition at line 3424 of file QueryPath.php.
References setMatches().
Referenced by __clone().
| closest | ( | $ | selector | ) |
Find the closest element matching the selector.
This finds the closest match in the ancestry chain. It first checks the present element. If the present element does not match, this traverses up the ancestry chain (e.g. checks each parent) looking for an item that matches.
It is provided for jQuery 1.3 compatibility.
| string | $selector | A CSS Selector to match. |
Definition at line 2393 of file QueryPath.php.
References qp(), is(), $selector, and setMatches().
| contents | ( | ) |
Get all child nodes (not just elements) of all items in the matched set.
It gets only the immediate children, not all nodes in the subtree.
This does not process iframes. Xinclude processing is dependent on the DOM implementation and configuration.
Definition at line 2327 of file QueryPath.php.
References $c, and setMatches().
| count | ( | ) |
Get the number of elements currently wrapped by this object.
Since QueryPath is Countable, the PHP count() function can also be used on a QueryPath.
Definition at line 735 of file QueryPath.php.
Referenced by is(), and removeClass().
| css | ( | $ | name = NULL, |
| $ | value = '' |
||
| ) |
Set/get a CSS value for the current element(s).
This sets the CSS value for each element in the QueryPath object. It does this by setting (or getting) the style attribute (without a namespace).
For example, consider this code:
This will return the following HTML:
<body style="background-color: red"/>
If no parameters are passed into this function, then the current style element will be returned unparsed. Example:
This will return the following:
background-color: red
As of QueryPath 2.1, existing style attributes will be merged with new attributes. (In previous versions of QueryPath, a call to css() overwrite the existing style values).
| mixed | $name | If this is a string, it will be used as a CSS name. If it is an array, this will assume it is an array of name/value pairs of CSS rules. It will apply all rules to all elements in the set. |
| string | $value | The value to set. This is only set if $name is a string. |
Definition at line 943 of file QueryPath.php.
References attr().
| dataURL | ( | $ | attr, |
| $ | data = NULL, |
||
| $ | mime = 'application/octet-stream', |
||
| $ | context = NULL |
||
| ) |
Insert or retrieve a Data URL.
When called with just $attr, it will fetch the result, attempt to decode it, and return an array with the MIME type and the application data.
When called with both $attr and $data, it will inject the data into all selected elements So
$qp->dataURL('src', file_get_contents('my.png'), 'image/png')
will inject the given PNG image into the selected elements.
The current implementation only knows how to encode and decode Base 64 data.
Note that this is known *not* to work on IE 6, but should render fine in other browsers.
| string | $attr | The name of the attribute. |
| mixed | $data | The contents to inject as the data. The value can be any one of the following:
|
| string | $mime | The MIME type of the document. |
| resource | $context | A valid context. Use this only if you need to pass a stream context. This is only necessary if $data is a URL. (See stream_context_create()). |
Definition at line 1023 of file QueryPath.php.
References $data, attr(), $matches, and encodeDataURL().
| deepest | ( | ) |
Reduce the set of matches to the deepest child node in the tree.
This loops through the matches and looks for the deepest child node of all of the matches. "Deepest", here, is relative to the nodes in the list. It is calculated as the distance from the starting node to the most distant child node. In other words, it is not necessarily the farthest node from the root element, but the farthest note from the matched element.
In the case where there are multiple nodes at the same depth, all of the nodes at that depth will be included.
Definition at line 1953 of file QueryPath.php.
References deepestNode(), and setMatches().
| deepestNode | ( | DOMNode $ | ele, |
| $ | depth = 0, |
||
| $ | current = NULL, |
||
| &$ | deepest = NULL |
||
| ) | [protected] |
A depth-checking function.
Typically, it only needs to be invoked with the first parameter. The rest are used for recursion.
| DOMNode | $ele | The element. |
| int | $depth | The depth guage |
| mixed | $current | The current set. |
| DOMNode | $deepest | A reference to the current deepest node. |
Definition at line 1991 of file QueryPath.php.
Referenced by wrap(), wrapAll(), wrapInner(), and deepest().
| detach | ( | $ | selector = NULL | ) |
Detach any items from the list if they match the selector.
In other words, each item that matches the selector will be remove from the DOM document. The returned QueryPath wraps the list of removed elements.
If no selector is specified, this will remove all current matches from the document.
| string | $selector | A CSS Selector. |
Definition at line 3466 of file QueryPath.php.
References $selector, find(), last(), and setMatches().
| document | ( | ) |
Get the DOMDocument that we currently work with.
This returns the current DOMDocument. Any changes made to this document will be accessible to QueryPath, as both will share access to the same object.
Definition at line 792 of file QueryPath.php.
Referenced by __construct(), top(), find(), xpath(), xinclude(), append(), prepareInsert(), replaceAll(), add(), html(), innerXHTML(), innerXML(), text(), textBefore(), textAfter(), xhtml(), xml(), writeXML(), and writeHTML().
| each | ( | $ | callback | ) |
Run a callback on each item in the list of items.
Rules of the callback:
| callback | $callback | The callback to run. |
Definition at line 1463 of file QueryPath.php.
References $i.
| eachLambda | ( | $ | lambda | ) |
An each() iterator that takes a lambda function.
| string | $lambda | The lambda function. This will be passed ($index, &$item). |
Definition at line 1488 of file QueryPath.php.
| emptyElement | ( | ) |
Empty everything within the specified element.
A convenience function for removeChildren(). This is equivalent to jQuery's empty() function. However, `empty` is a built-in in PHP, and cannot be used as a function name.
Definition at line 3567 of file QueryPath.php.
References removeChildren().
| static encodeDataURL | ( | $ | data, |
| $ | mime = 'application/octet-stream', |
||
| $ | context = NULL |
||
| ) | [static] |
A static function for transforming data into a Data URL.
This can be used to create Data URLs for injection into CSS, JavaScript, or other non-XML/HTML content. If you are working with QP objects, you may want to use dataURL() instead.
| mixed | $data | The contents to inject as the data. The value can be any one of the following:
|
| string | $mime | The MIME type of the document. |
| resource | $context | A valid context. Use this only if you need to pass a stream context. This is only necessary if $data is a URL. (See stream_context_create()). |
Definition at line 505 of file QueryPath.php.
References $data.
Referenced by dataURL(), and QueryPathTest\testEncodeDataURL().
| end | ( | ) |
Revert to the previous set of matches.
This will revert back to the last set of matches (before the last "destructive" set of operations). This undoes any change made to the set of matched objects. Functions like find() and filter() change the list of matched objects. The end() function will revert back to the last set of matched items.
Note that functions that modify the document, but do not change the list of matched objects, are not "destructive". Thus, calling append('something')->end() will not undo the append() call.
Only one level of changes is stored. Reverting beyond that will result in an empty set of matches. Example:
// The line below returns the same thing as qp(document, 'p'); qp(document, 'p')->find('div')->end(); // This returns an empty array: qp(document, 'p')->end(); // This returns an empty array: qp(document, 'p')->find('div')->find('span')->end()->end();
The last one returns an empty array because only one level of changes is stored.
Definition at line 2223 of file QueryPath.php.
References last().
| eq | ( | $ | index | ) |
Reduce the matched set to just one.
This will take a matched set and reduce it to just one item -- the item at the index specified. This is a destructive operation, and can be undone with end().
| $index | The index of the element to keep. The rest will be discarded. |
Definition at line 1091 of file QueryPath.php.
References setMatches().
| even | ( | ) |
Get the even elements, so counter-intuitively 1, 3, 5, etc.
Definition at line 3587 of file QueryPath.php.
References setMatches().
| filter | ( | $ | selector | ) |
Filter a list down to only elements that match the selector.
Use this, for example, to find all elements with a class, or with certain children.
| string | $selector | The selector to use as a filter. |
Definition at line 1158 of file QueryPath.php.
References qp(), is(), $selector, and setMatches().
Referenced by children(), and siblings().
| filterCallback | ( | $ | callback | ) |
Filter based on a callback function.
A callback may be any of the following:
Each callback is passed to arguments:
If the callback function returns FALSE, the item will be removed from the set of matches. Otherwise the item will be considered a match and left alone.
| callback | $callback,. | A callback either as a string (function) or an array (object, method OR classname, method). |
Definition at line 1275 of file QueryPath.php.
References $i, and setMatches().
| filterLambda | ( | $ | fn | ) |
Filter based on a lambda function.
The function string will be executed as if it were the body of a function. It is passed two arguments:
Example:
qp('li')->filterLambda('qp($item)->attr("id") == "test"');
The above would filter down the list to only an item whose ID is 'text'.
| string | $fn | Inline lambda function in a string. |
Definition at line 1190 of file QueryPath.php.
References $i, and setMatches().
| filterPreg | ( | $ | regex | ) |
Use regular expressions to filter based on the text content of matched elements.
Only items that match the given regular expression will be kept. All others will be removed.
The regular expression is run against the text content (the PCDATA) of the elements. This is a way of filtering elements based on their content.
Example:
<?xml version="1.0"?> <div>Hello <i>World</i></div>
<?php
// This will be 1.
qp($xml, 'div')->filterPreg('/World/')->size();
?>
The return value above will be 1 because the text content of ($xml, 'div') is World.
Compare this to the behavior of the :contains() CSS3 pseudo-class.
| string | $regex | A regular expression. |
Definition at line 1235 of file QueryPath.php.
References setMatches().
| find | ( | $ | selector | ) |
Given a CSS Selector, find matching items.
| string | $selector | CSS 3 Selector |
Definition at line 591 of file QueryPath.php.
References $selector, document(), setMatches(), and $i.
Referenced by __construct(), top(), and detach().
| first | ( | ) |
Get the first matching element.
Definition at line 3637 of file QueryPath.php.
References setMatches().
| firstChild | ( | ) |
Get the first child of the matching element.
Definition at line 3661 of file QueryPath.php.
References $c, and setMatches().
| get | ( | $ | index = NULL, |
| $ | asObject = FALSE |
||
| ) |
Get one or all elements from this object.
When called with no paramaters, this returns all objects wrapped by the QueryPath. Typically, these are DOMElement objects (unless you have used map(), xpath(), or other methods that can select non-elements).
When called with an index, it will return the item in the QueryPath with that index number.
Calling this method does not change the QueryPath (e.g. it is non-destructive).
You can use qp()->get() to iterate over all elements matched. You can also iterate over qp() itself (QueryPath implementations must be Traversable). In the later case, though, each item will be wrapped in a QueryPath object. To learn more about iterating in QueryPath, see examples/techniques.php.
| int | $index | If specified, then only this index value will be returned. If this index is out of bounds, a NULL will be returned. |
| boolean | $asObject | If this is TRUE, an SplObjectStorage object will be returned instead of an array. This is the preferred method for extensions to use. |
Definition at line 771 of file QueryPath.php.
References size(), and $matches.
Referenced by __construct().
| getIterator | ( | ) |
Dynamically generate certain properties.
This is used primarily to increase jQuery compatibility by providing property-like behaviors.
Currently defined properties:
Definition at line 4219 of file QueryPath.php.
References $i.
| getOptions | ( | ) |
Get the effective options for the current QueryPath object.
This returns an associative array of all of the options as set for the current QueryPath object. This includes default options, options directly passed in via qp() or the constructor, an options set in the QueryPathOptions object.
The order of merging options is this:
This function will return the options currently used, with the above option overriding having been calculated already.
Definition at line 544 of file QueryPath.php.
| has | ( | $ | contained | ) |
Reduce the elements matched by QueryPath to only those which contain the given item.
There are two ways in which this is different from jQuery's implementation:
| mixed | $contained |
|
Definition at line 3522 of file QueryPath.php.
References branch(), and setMatches().
| hasAttr | ( | $ | attrName | ) |
Check to see if the given attribute is present.
This returns TRUE if all selected items have the attribute, or FALSE if at least one item does not have the attribute.
| string | $attrName | The attribute name. |
Definition at line 896 of file QueryPath.php.
| hasClass | ( | $ | class | ) |
Returns TRUE if any of the elements in the QueryPath have the specified class.
| string | $class | The name of the class. |
Definition at line 3329 of file QueryPath.php.
| html | ( | $ | markup = NULL | ) |
Set or get the markup for an element.
If $markup is set, then the giving markup will be injected into each item in the set. All other children of that node will be deleted, and this new code will be the only child or children. The markup MUST BE WELL FORMED.
If no markup is given, this will return a string representing the child markup of the first node.
Important: This differs from jQuery's html() function. This function returns the current node and all of its children. jQuery returns only the children. This means you do not need to do things like this:
$qp->parent()->html()
.
By default, this is HTML 4.01, not XHTML. Use xml() for XHTML.
| string | $markup | The text to insert. |
Definition at line 2509 of file QueryPath.php.
References QueryPathEntities\replaceAllEntities(), $doc, document(), removeChildren(), append(), $length, and size().
| index | ( | $ | subject | ) |
Get an item's index.
Given a DOMElement, get the index from the matches. This is the converse of get().
| DOMElement | $subject | The item to match. |
Definition at line 1332 of file QueryPath.php.
References $i.
| innerHTML | ( | ) |
Fetch the HTML contents INSIDE of the first QueryPath item.
This behaves the way jQuery's () function behaves.
This gets all children of the first match in QueryPath.
Consider this fragment:
<div> test <p>foo</p> test </div>
We can retrieve just the contents of this code by doing something like this:
qp($xml, 'div')->innerHTML();
This would return the following:
foo test
Definition at line 2579 of file QueryPath.php.
References innerXML().
| innerXHTML | ( | ) |
Fetch child (inner) nodes of the first match.
This will return the children of the present match. For an example, see innerHTML().
Definition at line 2596 of file QueryPath.php.
References $length, size(), and document().
| innerXML | ( | ) |
Fetch child (inner) nodes of the first match.
This will return the children of the present match. For an example, see innerHTML().
Definition at line 2633 of file QueryPath.php.
References $length, size(), and document().
Referenced by innerHTML().
| insertAfter | ( | QueryPath $ | dest | ) |
Insert the contents of the current QueryPath after the nodes in the destination QueryPath object.
| QueryPath | $dest | Destination object where the current elements will be deposited. |
| QueryPathException | Thrown if $data is an unsupported object type. |
Definition at line 1687 of file QueryPath.php.
References after().
| insertBefore | ( | QueryPath $ | dest | ) |
Insert the current elements into the destination document.
The items are inserted before each element in the given QueryPath document. That is, they will be siblings with the current elements.
| QueryPathException | Thrown if $data is an unsupported object type. |
Definition at line 1669 of file QueryPath.php.
References before().
| is | ( | $ | selector | ) |
Given a selector, this checks to see if the current set has one or more matches.
Unlike jQuery's version, this supports full selectors (not just simple ones).
| string | $selector | The selector to search for. As of QueryPath 2.1.1, this also supports passing a DOMNode object. |
Definition at line 1109 of file QueryPath.php.
References $selector, and count().
Referenced by filter(), not(), closest(), parent(), parents(), next(), nextAll(), prev(), prevAll(), peers(), nextUntil(), prevUntil(), and parentsUntil().
| isXMLish | ( | $ | string | ) | [protected] |
Determine whether a given string looks like XML or not.
Basically, this scans a portion of the supplied string, checking to see if it has a tag-like structure. It is possible to "confuse" this, which may subsequently result in parse errors, but in the vast majority of cases, this method serves as a valid inicator of whether or not the content looks like XML.
Things that are intentional excluded:
Subclasses SHOULD NOT OVERRIDE THIS. Altering it may be altering core assumptions about how things work. Instead, classes should override the constructor and pass in only one of the parsed types that this class expects.
Definition at line 3873 of file QueryPath.php.
Referenced by __construct(), and XMLishMock\exposedIsXMLish().
| last | ( | ) |
Get the last matching element.
Definition at line 3691 of file QueryPath.php.
References setMatches().
Referenced by add(), end(), andSelf(), detach(), attach(), and setMatches().
| lastChild | ( | ) |
Get the last child of the matching element.
Definition at line 3718 of file QueryPath.php.
References $c, and setMatches().
| map | ( | $ | callback | ) |
Run a function on each item in a set.
The mapping callback can return anything. Whatever it returns will be stored as a match in the set, though. This means that afer a map call, there is no guarantee that the elements in the set will behave correctly with other QueryPath functions.
Callback rules:
| callback | $callback | The function or callback to use. The callback will be passed two params:
|
Definition at line 1371 of file QueryPath.php.
References $i, $c, and setMatches().
| next | ( | $ | selector = NULL | ) |
Get the next sibling of each element in the QueryPath.
If a selector is provided, the next matching sibling will be returned.
| string | $selector | A CSS3 selector. |
Definition at line 3085 of file QueryPath.php.
References $selector, qp(), is(), and setMatches().
| nextAll | ( | $ | selector = NULL | ) |
Get all siblings after an element.
For each element in the QueryPath, get all siblings that appear after it. If a selector is passed in, then only siblings that match the selector will be included.
| string | $selector | A valid CSS 3 selector. |
Definition at line 3123 of file QueryPath.php.
References $selector, qp(), is(), and setMatches().
| nextUntil | ( | $ | selector = NULL | ) |
Get all siblings after an element until the selector is reached.
For each element in the QueryPath, get all siblings that appear after it. If a selector is passed in, then only siblings that match the selector will be included.
| string | $selector | A valid CSS 3 selector. |
Definition at line 3755 of file QueryPath.php.
References $selector, qp(), is(), and setMatches().
| not | ( | $ | selector | ) |
Filter a list to contain only items that do NOT match.
| string | $selector | A selector to use as a negation filter. If the filter is matched, the element will be removed from the list. |
Definition at line 1298 of file QueryPath.php.
References $selector, qp(), is(), and setMatches().
| odd | ( | ) |
Get the odd elements, so counter-intuitively 0, 2, 4, etc.
Definition at line 3614 of file QueryPath.php.
References setMatches().
| parent | ( | $ | selector = NULL | ) |
Get the immediate parent of each element in the QueryPath.
If a selector is passed, this will return the nearest matching parent for each element in the QueryPath.
| string | $selector | A valid CSS3 selector. |
Definition at line 2429 of file QueryPath.php.
References $selector, qp(), is(), and setMatches().
| parents | ( | $ | selector = NULL | ) |
Get all ancestors of each element in the QueryPath.
If a selector is present, only matching ancestors will be retrieved.
| string | $selector | A valid CSS 3 Selector. |
Definition at line 2465 of file QueryPath.php.
References $selector, qp(), is(), and setMatches().
| parentsUntil | ( | $ | selector = NULL | ) |
Get all ancestors of each element in the QueryPath until the selector is reached.
If a selector is present, only matching ancestors will be retrieved.
| string | $selector | A valid CSS 3 Selector. |
Definition at line 3830 of file QueryPath.php.
References $selector, qp(), is(), and setMatches().
| peers | ( | $ | selector = NULL | ) |
Definition at line 3221 of file QueryPath.php.
References $selector, qp(), is(), and setMatches().
| prepareInsert | ( | $ | item | ) | [protected] |
Prepare an item for insertion into a DOM.
This handles a variety of boilerplate tasks that need doing before an indeterminate object can be inserted into a DOM tree.
| mixed | $item | Item to prepare for insert. |
| QueryPathException | Thrown if the object passed in is not of a supprted object type. |
Definition at line 2031 of file QueryPath.php.
References QueryPathEntities\replaceAllEntities(), and document().
Referenced by append(), prepend(), before(), after(), replaceWith(), wrap(), wrapAll(), and wrapInner().
| prepend | ( | $ | data | ) |
Insert the given markup as the first child.
The markup will be inserted into each match in the set.
| mixed | $data | This can be either a string (the usual case), or a DOM Element. |
| QueryPathException | Thrown if $data is an unsupported object type. |
Definition at line 1588 of file QueryPath.php.
References $data, and prepareInsert().
Referenced by prependTo().
| prependTo | ( | QueryPath $ | dest | ) |
Take all nodes in the current object and prepend them to the children nodes of each matched node in the passed-in QueryPath object.
This will iterate through each item in the current QueryPath object and add each item to the beginning of the children of each element in the passed-in QueryPath object.
| QueryPathException | Thrown if $data is an unsupported object type. |
Definition at line 1620 of file QueryPath.php.
References prepend().
| prev | ( | $ | selector = NULL | ) |
Get the next sibling before each element in the QueryPath.
For each element in the QueryPath, this retrieves the previous sibling (if any). If a selector is supplied, it retrieves the first matching sibling (if any is found).
| string | $selector | A valid CSS 3 selector. |
Definition at line 3160 of file QueryPath.php.
References $selector, qp(), is(), and setMatches().
| prevAll | ( | $ | selector = NULL | ) |
Get the previous siblings for each element in the QueryPath.
For each element in the QueryPath, get all previous siblings. If a selector is provided, only matching siblings will be retrieved.
| string | $selector | A valid CSS 3 selector. |
Definition at line 3198 of file QueryPath.php.
References $selector, qp(), is(), and setMatches().
| prevUntil | ( | $ | selector = NULL | ) |
Get the previous siblings for each element in the QueryPath until the selector is reached.
For each element in the QueryPath, get all previous siblings. If a selector is provided, only matching siblings will be retrieved.
| string | $selector | A valid CSS 3 selector. |
Definition at line 3798 of file QueryPath.php.
References $selector, qp(), is(), and setMatches().
| remove | ( | $ | selector = NULL | ) |
Remove any items from the list if they match the selector.
In other words, each item that matches the selector will be remove from the DOM document. The returned QueryPath wraps the list of removed elements.
If no selector is specified, this will remove all current matches from the document.
| string | $selector | A CSS Selector. |
Definition at line 2107 of file QueryPath.php.
| removeAttr | ( | $ | name | ) |
Remove the named attribute from all elements in the current QueryPath.
This will remove any attribute with the given name. It will do this on each item currently wrapped by QueryPath.
As is the case in jQuery, this operation is not considered destructive.
| string | $name | Name of the parameter to remove. |
Definition at line 1069 of file QueryPath.php.
| removeChildren | ( | ) |
Remove all child nodes.
This is equivalent to jQuery's empty() function. (However, empty() is a PHP built-in, and cannot be used as a method name.)
Definition at line 2269 of file QueryPath.php.
Referenced by html(), text(), xml(), and emptyElement().
| removeClass | ( | $ | class | ) |
Remove the named class from any element in the QueryPath that has it.
This may result in the entire class attribute being removed. If there are other items in the class attribute, though, they will not be removed.
Example: Consider this XML:
<element class="first second"/>
Executing this fragment of code will remove only the 'first' class:
The resulting XML will be:
<element class="second"/>
To remove the entire 'class' attribute, you should use {
| string | $class | The class name to remove. |
Definition at line 3301 of file QueryPath.php.
References count().
| replaceAll | ( | $ | selector, |
| DOMDocument $ | document | ||
| ) |
This replaces everything that matches the selector with the first value in the current list.
This is the reverse of replaceWith.
Unlike jQuery, QueryPath cannot assume a default document. Consequently, you must specify the intended destination document. If it is omitted, the present document is assumed to be tthe document. However, that can result in undefined behavior if the selector and the replacement are not sufficiently distinct.
| string | $selector | The selector. |
| DOMDocument | $document | The destination document. |
Definition at line 2152 of file QueryPath.php.
References size(), document(), $c, $selector, and qp().
| replaceWith | ( | $ | new | ) |
Replace the existing element(s) in the list with a new one.
| mixed | $new | A DOMElement or XML in a string. This will replace all elements currently wrapped in the QueryPath object. |
Definition at line 1734 of file QueryPath.php.
References $data, prepareInsert(), and setMatches().
| setMatches | ( | $ | matches, |
| $ | unique = TRUE |
||
| ) |
EXPERT: Be very, very careful using this.
A utility function for setting the current set of matches. It makes sure the last matches buffer is set (for end() and andSelf()).
Definition at line 3949 of file QueryPath.php.
References last(), and $matches.
Referenced by __construct(), top(), find(), xpath(), eq(), filter(), filterLambda(), filterPreg(), filterCallback(), not(), map(), slice(), append(), replaceWith(), deepest(), children(), contents(), siblings(), closest(), parent(), parents(), next(), nextAll(), prev(), prevAll(), peers(), cloneAll(), detach(), has(), even(), odd(), first(), firstChild(), last(), lastChild(), nextUntil(), prevUntil(), and parentsUntil().
| siblings | ( | $ | selector = NULL | ) |
Get a list of siblings for elements currently wrapped by this object.
This will compile a list of every sibling of every element in the current list of elements.
Note that if two siblings are present in the QueryPath object to begin with, then both will be returned in the matched set, since they are siblings of each other. In other words,if the matches contain a and b, and a and b are siblings of each other, than running siblings will return a set that contains both a and b.
| string | $selector | If the optional selector is provided, siblings will be filtered through this expression. |
Definition at line 2360 of file QueryPath.php.
References $selector, setMatches(), and filter().
| size | ( | ) |
Get the number of elements currently wrapped by this object.
Note that there is no length property on this object.
Definition at line 716 of file QueryPath.php.
Referenced by get(), slice(), tag(), replaceAll(), html(), innerXHTML(), innerXML(), xhtml(), and xml().
| slice | ( | $ | start, |
| $ | length = 0 |
||
| ) |
Narrow the items in this object down to only a slice of the starting items.
| integer | $start | Where in the list of matches to begin the slice. |
| integer | $length | The number of items to include in the slice. If nothing is specified, the all remaining matches (from $start onward) will be included in the sliced list. |
Definition at line 1419 of file QueryPath.php.
References $length, size(), setMatches(), and $i.
| tag | ( | ) |
The tag name of the first element in the list.
This returns the tag name of the first element in the list of matches. If the list is empty, an empty string will be used.
Definition at line 2086 of file QueryPath.php.
References size().
| text | ( | $ | text = NULL | ) |
Get or set the text contents of a node.
| string | $text | If this is not NULL, this value will be set as the text of the node. It will replace any existing content. |
Definition at line 2718 of file QueryPath.php.
References removeChildren(), and document().
| textAfter | ( | $ | text = NULL | ) |
Definition at line 2772 of file QueryPath.php.
References document(), and after().
| textBefore | ( | $ | text = NULL | ) |
Get or set the text before each selected item.
If $text is passed in, the text is inserted before each currently selected item.
If no text is given, this will return the concatenated text after each selected element.
<?php $xml = '<?xml version="1.0"?><root>Foo<a>Bar</a><b/></root>'; // This will return 'Foo' qp($xml, 'a')->textBefore(); // This will insert 'Baz' right before <b/>. qp($xml, 'b')->textBefore('Baz'); ?>
| string | $text | If this is set, it will be inserted before each node in the current set of selected items. |
Definition at line 2756 of file QueryPath.php.
References document(), before(), and $p.
| textImplode | ( | $ | sep = ', |
| ' | , | ||
| $ | filterEmpties = TRUE |
||
| ) |
Retrieve the text of each match and concatenate them with the given separator.
This has the effect of looping through all children, retrieving their text content, and then concatenating the text with a separator.
| string | $sep | The string used to separate text items. The default is a comma followed by a space. |
| boolean | $filterEmpties | If this is true, empty items will be ignored. |
Definition at line 2675 of file QueryPath.php.
| toArray | ( | ) |
Get all current elements wrapped in an array.
Compatibility function for jQuery 1.4, but identical to calling get() with no parameters.
Definition at line 814 of file QueryPath.php.
| top | ( | $ | selector = NULL | ) |
Select the root element of the document.
This sets the current match to the document's root element. For practical purposes, this is the same as:
qp($someDoc)->find(':root');
However, since it doesn't invoke a parser, it has less overhead. It also works in cases where the QueryPath has been reduced to zero elements (a case that is not handled by find(':root') because there is no element whose root can be found).
| string | $selector | A selector. If this is supplied, QueryPath will navigate to the document root and then run the query. (Added in QueryPath 2.0 Beta 2) |
Definition at line 568 of file QueryPath.php.
References setMatches(), document(), $selector, and find().
| unwrap | ( | ) |
Remove the parent element from the selected node or nodes.
This takes the given list of nodes and "unwraps" them, moving them out of their parent node, and then deleting the parent node.
For example, consider this:
<root><wrapper><content/></wrapper></root>
Now we can run this code:
qp($xml, 'content')->unwrap();
This will result in:
<root><content/></root>
This is the opposite of wrap().
The root element cannot be unwrapped. It has no parents. If you attempt to use unwrap on a root element, this will throw a QueryPathException. (You can, however, "Unwrap" a child that is a direct descendant of the root element. This will remove the root element, and replace the child as the root element. Be careful, though. You cannot set more than one child as a root element.)
| QueryPathException | An exception is thrown if one attempts to unwrap a root element. |
Definition at line 1783 of file QueryPath.php.
| val | ( | $ | value = NULL | ) |
Set or get the value of an element's 'value' attribute.
The 'value' attribute is common in HTML form elements. This is a convenience function for accessing the values. Since this is not common task on the server side, this method may be removed in future releases. (It is currently provided for jQuery compatibility.)
If a value is provided in the params, then the value will be set for all matches. If no params are given, then the value of the first matched element will be returned. This may be NULL.
| string | $value |
Definition at line 2807 of file QueryPath.php.
References attr().
| wrap | ( | $ | markup | ) |
Wrap each element inside of the given markup.
Markup is usually a string, but it can also be a DOMNode, a document fragment, a SimpleXMLElement, or another QueryPath object (in which case the first item in the list will be used.)
| mixed | $markup | Markup that will wrap each element in the current list. |
Definition at line 1826 of file QueryPath.php.
References $data, prepareInsert(), and deepestNode().
| wrapAll | ( | $ | markup | ) |
Wrap all elements inside of the given markup.
So all elements will be grouped together under this single marked up item. This works by first determining the parent element of the first item in the list. It then moves all of the matching elements under the wrapper and inserts the wrapper where that first element was found. (This is in accordance with the way jQuery works.)
Markup is usually XML in a string, but it can also be a DOMNode, a document fragment, a SimpleXMLElement, or another QueryPath object (in which case the first item in the list will be used.)
| string | $markup | Markup that will wrap all elements in the current list. |
Definition at line 1874 of file QueryPath.php.
References $data, prepareInsert(), and deepestNode().
| wrapInner | ( | $ | markup | ) |
Wrap the child elements of each item in the list with the given markup.
Markup is usually a string, but it can also be a DOMNode, a document fragment, a SimpleXMLElement, or another QueryPath object (in which case the first item in the list will be used.)
| string | $markup | Markup that will wrap children of each element in the current list. |
Definition at line 1913 of file QueryPath.php.
References $data, prepareInsert(), and deepestNode().
| writeHTML | ( | $ | path = NULL | ) |
Writes HTML to output.
HTML is formatted as HTML 4.01, without strict XML unary tags. This is for legacy HTML content. Modern XHTML should be written using toXHTML().
Write the document to stdout (usually the client) or to a file.
| string | $path | The path to the file into which the XML should be written. if this is NULL, data will be written to STDOUT, which is usually sent to the remote browser. |
| Exception | In the event that a file cannot be written, an Exception will be thrown. |
Definition at line 3007 of file QueryPath.php.
References $path, print, and document().
| writeXHTML | ( | $ | path = NULL | ) |
Write an XHTML file to output.
Typically, you should use this instead of writeHTML().
Currently, this functions identically to toXML() except that it always uses closing tags (e.g. always
<script></script>
, never
<script/>
). It will write the file as well-formed XML. No XHTML schema validation is done.
| string | $path | The filename of the file to write to. |
| Exception | In the event that the output file cannot be written, an exception is thrown. |
Definition at line 3049 of file QueryPath.php.
References writeXML(), and $path.
| writeXML | ( | $ | path = NULL, |
| $ | options = NULL |
||
| ) |
Send the XML document to the client.
Write the document to a file path, if given, or to stdout (usually the client).
This prints the entire document.
| string | $path | The path to the file into which the XML should be written. if this is NULL, data will be written to STDOUT, which is usually sent to the remote browser. |
| int | $options | (As of QueryPath 2.1) Pass libxml options to the saving mechanism. |
| Exception | In the event that a file cannot be written, an Exception will be thrown. |
Definition at line 2971 of file QueryPath.php.
References $path, print, and document().
Referenced by writeXHTML().
| xhtml | ( | $ | markup = NULL | ) |
Set or get XHTML markup for an element or elements.
This differs from html() in that it processes (and produces) strictly XML 1.0 compliant markup.
Like xml() and html(), this functions as both a setter and a getter.
This is a convenience function for fetching HTML in XML format. It does no processing of the markup (such as schema validation).
| string | $markup | A string containing XML data. |
Definition at line 2833 of file QueryPath.php.
References xml(), $length, size(), and document().
| xinclude | ( | ) |
On an XML document, load all XIncludes.
Definition at line 801 of file QueryPath.php.
References document().
| xml | ( | $ | markup = NULL | ) |
Set or get the XML markup for an element or elements.
Like html(), this functions in both a setter and a getter mode.
In setter mode, the string passed in will be parsed and then appended to the elements wrapped by this QueryPath object.When in setter mode, this parses the XML using the DOMFragment parser. For that reason, an XML declaration is not necessary.
In getter mode, the first element wrapped by this QueryPath object will be converted to an XML string and returned.
| string | $markup | A string containing XML data. |
Definition at line 2914 of file QueryPath.php.
References QueryPathEntities\replaceAllEntities(), $doc, document(), removeChildren(), append(), $length, and size().
Referenced by xhtml().
| xpath | ( | $ | query, |
| $ | options = array() |
||
| ) |
Execute an XPath query and store the results in the QueryPath.
Most methods in this class support CSS 3 Selectors. Sometimes, though, XPath provides a finer-grained query language. Use this to execute XPath queries.
Beware, though. QueryPath works best on DOM Elements, but an XPath query can return other nodes, strings, and values. These may not work with other QueryPath functions (though you will be able to access the values with get()).
| string | $query | An XPath query. |
| array | $options | Currently supported options are:
|
Definition at line 688 of file QueryPath.php.
References document(), $i, and setMatches().
$document = NULL [protected] |
$last = array() [protected] |
| $length = 0 |
The number of current matches.
Definition at line 380 of file QueryPath.php.
Referenced by slice(), html(), innerXHTML(), innerXML(), xhtml(), and xml().
$matches = array() [protected] |
The array of matches.
Definition at line 368 of file QueryPath.php.
Referenced by get(), dataURL(), remove(), and setMatches().
| const DEFAULT_PARSER_FLAGS = NULL |
Default parser flags.
These are flags that will be used if no global or local flags override them.
Definition at line 343 of file QueryPath.php.
Referenced by __construct().
| const HTML_STUB |
'<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Untitled</title> </head> <body></body> </html>'
This is a stub HTML 4.01 document.
Using QueryPath::XHTML_STUB is preferred.
This is primarily for generating legacy HTML content. Modern web applications should use QueryPath::XHTML_STUB.
Use this stub with the HTML familiy of methods (html(), writeHTML(), innerHTML()).
Definition at line 302 of file QueryPath.php.
Referenced by QPDBTest\testQueryInto(), QPDBTest\testQueryChains(), QPListTests\testAppendList(), QPListTests\testAppendTable(), QPTPLTest\testTplRecursion(), QPTPLTest\testTplTraversable(), QueryPathTest\testQueryPathHtmlConstructors(), QueryPathTest\testNext(), QueryPathTest\testBranch(), QueryPathTest\testStub(), and QueryPathTest\testIterator().
| const JS_CSS_ESCAPE_CDATA = '\\1' |
Definition at line 345 of file QueryPath.php.
| const JS_CSS_ESCAPE_CDATA_CCOMMENT = '/* \\1 */' |
Definition at line 346 of file QueryPath.php.
| const JS_CSS_ESCAPE_CDATA_DOUBLESLASH = '// \\1' |
Definition at line 347 of file QueryPath.php.
| const JS_CSS_ESCAPE_NONE = '' |
Definition at line 348 of file QueryPath.php.
| const VERSION = '2.1.1' |
The version string for this version of QueryPath.
Standard releases will be of the following form: <MAJOR>.<MINOR>[.<PATCH>][-STABILITY].
Examples:
Developer releases will always be of the form dev-<DATE>.
Definition at line 289 of file QueryPath.php.
| const XHTML_STUB |
'<?xml version="1.0"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>Untitled</title> </head> <body></body> </html>'
This is a stub XHTML document.
Since XHTML is an XML format, you should use XML functions with this document fragment. For example, you should use xml(), innerXML(), and writeXML().
This can be passed into qp() to begin a new basic HTML document.
Example:
$qp = qp(QueryPath::XHTML_STUB); // Creates a new XHTML document $qp->writeXML(); // Writes the document as well-formed XHTML.
Definition at line 327 of file QueryPath.php.