PACK WOC
$VERSION$
|
DOM Query Class. More...
#include <domquery.h>
Public Member Functions | |
MDomQuery (const QDomElement &start, QString path) | |
creates the query object and executes the query More... | |
MDomQuery (const QDomDocument &start, QString path) | |
creates the query object and executes the query; this is equivalent to calling the query with the document element as starting point More... | |
QString | toString () const |
returns the search result as a single string, if there were multiple matches, they are separated by spaces More... | |
QStringList | toStringList () const |
returns the search result as a list of strings, one string element per match More... | |
MDomNodeList | toNodeList () const |
returns the result as a list of DOM nodes More... | |
operator QString () const | |
cast to QString: see toString() More... | |
operator QStringList () const | |
cast to QStringList: see toStringList() More... | |
operator MDomNodeList () const | |
cast to DOM node list: see toNodeList() More... | |
Private Member Functions | |
void | construct (const QDomElement &start, QString path) |
Private Attributes | |
MDomNodeList | m_result |
DOM Query Class.
It uses a simplified version of the XPath syntax:
Namespaces/Prefixes are ignored. It is recommended to use patternist for cases in which namespaces matter.
The search path uses slash "/" to separate elements, the last item in the search path may start with "@" to match an attribute instead of an element. The special names "*" and "@*" may be used to match any element or attribute. If the search path starts with a slash "/", the search starts at the document root irrespective of what element was fed to the query object (the first item matched against the root element). If the search path starts with a double slash "//" the search considers all positions in the document as valid starting points (using all elements that match the first item to start the search, the first item must not be "*" in that case). If there is no slash at the start of the path the search begins exactly at the supplied element (the first item matched against child elements of the supplied element). Queries that start with a slash must search an element at the first position.
When casting to QString or QStringList the query object uses the method text() of the QDomElement to generate the content of the element. For attributes it simply returns the value.
Examples:
mouse | return all child elements of the current element that are called "mouse" |
@mouse | return all attribute nodes of the current element that are called "mouse" |
* | returns all child elements of the current element |
@* | returns all attributes of the current element |
/* | returns the root element of the document irrespective of name |
/mouse | returns the root element of the document if it has the tag name "mouse" or an empty list |
/*/mouse | returns all elements directly below the root element that are called "mouse" |
//mouse | returns all elements in the document that are called "mouse" |
mouse/@trap/door | syntax error, attributes cannot have children |
MDomQuery::MDomQuery | ( | const QDomElement & | start, |
QString | path | ||
) |
creates the query object and executes the query
MDomQuery::MDomQuery | ( | const QDomDocument & | start, |
QString | path | ||
) |
creates the query object and executes the query; this is equivalent to calling the query with the document element as starting point
|
private |
|
inline |
cast to DOM node list: see toNodeList()
|
inline |
cast to QString: see toString()
|
inline |
cast to QStringList: see toStringList()
|
inline |
returns the result as a list of DOM nodes
QString MDomQuery::toString | ( | ) | const |
returns the search result as a single string, if there were multiple matches, they are separated by spaces
QStringList MDomQuery::toStringList | ( | ) | const |
returns the search result as a list of strings, one string element per match
|
private |