QHtmlParser  0.0.1
A Qt/C++ library for parsing and traversing/searching HTML documents.
Public Member Functions | List of all members
QHtmlAttributeMatch Class Reference

Defines the criteria used for performing a match against the attributes of an element. More...

#include <qhtmlparser.h>

Inheritance diagram for QHtmlAttributeMatch:
QHtmlAttribute

Public Member Functions

 QHtmlAttributeMatch ()
 Constructs a QHtmlAttributeMatch with an empty name and value.
 
 QHtmlAttributeMatch (const QString &name, const QString &value, QHtmlParser::MatchFlags flags=QHtmlParser::MatchFlags(QHtmlParser::MatchExactly))
 Constructs a QHtmlAttributeMatch using the specified name, value and flags.
 
QHtmlParser::MatchFlags flags () const
 Returns the flags set for the attribute match. More...
 
void setFlags (QHtmlParser::MatchFlags flags)
 Sets the flags for the attribute match to flags. More...
 
void setFlag (QHtmlParser::MatchFlag flag, bool on=true)
 Sets or unsets the flag depending of the value of on (default is true). More...
 
bool testFlag (QHtmlParser::MatchFlag flag) const
 Returns true if flag is set. More...
 
bool operator== (const QHtmlAttributeMatch &other) const
 Returns true if name(), value() and flags() of other are equal to those of this QHtmlAttributeMatch.
 
bool operator!= (const QHtmlAttributeMatch &other) const
 Returns true if either name(), value() or flags() of other are not equal to those of this QHtmlAttributeMatch.
 
- Public Member Functions inherited from QHtmlAttribute
 QHtmlAttribute ()
 Constructs a QHtmlAttribute with an empty name and value.
 
 QHtmlAttribute (const QString &name, const QString &value)
 Constructs a QHtmlAttribute using the specified name and value.
 
const QString & name () const
 Returns the name of the attribute.
 
void setName (const QString &name)
 Sets the name of the attribute to name.
 
const QString & value () const
 Returns the value of the attribute.
 
void setValue (const QString &value)
 Sets the value of the attribute to value.
 
bool operator== (const QHtmlAttribute &other) const
 Returns true if both name() and value() of other are equal to those of this QHtmlAttribute.
 
bool operator!= (const QHtmlAttribute &other) const
 Returns true if either name() or value() of other are not equal to those of this QHtmlAttribute.
 

Detailed Description

Defines the criteria used for performing a match against the attributes of an element.

The QHtmlAttributeMatch class is used to define the criteria that is applied when performing a match against the attributes of a QHtmlElement.

A match is performed by looking for any attribute of the QHtmlElement that has the same name as the QHtmlAttributeMatch, and a value that matches the criteria defined by value() and flags(). The value may be a string or regular expression pattern. The manner in which the value is matched against attributes is determined by the flags, which may be a bitwise OR combination of the QHtmlParser::MatchFlag enum values.

Example usage:

QFile file("document.html");
file.open(QFile::ReadOnly);
const QHtmlDocument document(&file);
const QHtmlElement root = document.documentElement();
const QHtmlAttributeMatch dataMatch("data-foo", "bar", QHtmlParser::MatchContains);
const QHtmlAttributeMatches matches = QHtmlAttributeMatches() << classMatch << dataMatch;
const QHtmlElementList elements = root.elementsByTagName("div", matches);
foreach (const QHtmlElement &element, elements) {
// process element
}

Member Function Documentation

§ flags()

QHtmlParser::MatchFlags QHtmlAttributeMatch::flags ( ) const

Returns the flags set for the attribute match.

See also
testFlag()

§ setFlags()

void QHtmlAttributeMatch::setFlags ( QHtmlParser::MatchFlags  flags)

Sets the flags for the attribute match to flags.

See also
setFlag()

§ setFlag()

void QHtmlAttributeMatch::setFlag ( QHtmlParser::MatchFlag  flag,
bool  on = true 
)

Sets or unsets the flag depending of the value of on (default is true).

See also
setFlags()

§ testFlag()

bool QHtmlAttributeMatch::testFlag ( QHtmlParser::MatchFlag  flag) const

Returns true if flag is set.

See also
flags()

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