PACK WOC  $VERSION$
Public Member Functions | Private Member Functions | Private Attributes | List of all members
MDomQuery Class Reference

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
 

Detailed Description

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:

mousereturn all child elements of the current element that are called "mouse"
@mousereturn 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
/mousereturns the root element of the document if it has the tag name "mouse" or an empty list
/*/mousereturns all elements directly below the root element that are called "mouse"
//mousereturns all elements in the document that are called "mouse"
mouse/@trap/doorsyntax error, attributes cannot have children

Constructor & Destructor Documentation

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

Member Function Documentation

void MDomQuery::construct ( const QDomElement &  start,
QString  path 
)
private
MDomQuery::operator MDomNodeList ( ) const
inline

cast to DOM node list: see toNodeList()

MDomQuery::operator QString ( ) const
inline

cast to QString: see toString()

MDomQuery::operator QStringList ( ) const
inline

cast to QStringList: see toStringList()

MDomNodeList MDomQuery::toNodeList ( ) const
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

Member Data Documentation

MDomNodeList MDomQuery::m_result
private

The documentation for this class was generated from the following files: