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

Represents a HTML document. More...

#include <qhtmlparser.h>

Public Member Functions

 QHtmlDocument ()
 Constructs a null QHtmlDocument.
 
 QHtmlDocument (const QString &content)
 Constructs a QHtmlDocument and sets the document content to content. More...
 
 QHtmlDocument (const QByteArray &content)
 Constructs a QHtmlDocument and sets the document content to content. More...
 
 QHtmlDocument (QIODevice *device)
 Constructs a QHtmlDocument and sets the document content to the data contained in device. More...
 
 ~QHtmlDocument ()
 Destroys the QHtmlDocument. More...
 
bool setContent (const QString &content)
 Sets the document content to content. More...
 
bool setContent (const QByteArray &content)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
bool setContent (QIODevice *device)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Sets the document content to the data contained in device. More...
 
QHtmlElement documentElement () const
 Returns the root element of the document. More...
 
QHtmlElement htmlElement () const
 Returns the html element of the document (the element with tag name 'html'). More...
 
QHtmlElement headElement () const
 Returns the head element of the document (the element with tag name 'head'). More...
 
QHtmlElement bodyElement () const
 Returns the body element of the document (the element with tag name 'body'). More...
 
QString toString () const
 Returns the HTML string of the document. More...
 
bool hasError () const
 Returns true if an error occurred when parsing the document.
 
QString errorString () const
 Returns a description of any error that occurred when parsing the document. More...
 
bool isNull () const
 Returns true if the document is null. More...
 

Detailed Description

Represents a HTML document.

The QHtmlDocument class is used for loading and parsing a HTML document.

Example usage:

QFile file("document.html");
file.open(QFile::ReadOnly);
QHtmlDocument document;
if (!document.setContent(&file)) {
qDebug() << "Error:" << document.errorString();
return;
}
const QHtmlElement body = document.bodyElement();
foreach (const QHtmlElement &element, body.childElements()) {
// process element
}

Constructor & Destructor Documentation

§ QHtmlDocument() [1/3]

QHtmlDocument::QHtmlDocument ( const QString &  content)
explicit

Constructs a QHtmlDocument and sets the document content to content.

See also
setContent()

§ QHtmlDocument() [2/3]

QHtmlDocument::QHtmlDocument ( const QByteArray &  content)
explicit

Constructs a QHtmlDocument and sets the document content to content.

See also
setContent()

§ QHtmlDocument() [3/3]

QHtmlDocument::QHtmlDocument ( QIODevice *  device)
explicit

Constructs a QHtmlDocument and sets the document content to the data contained in device.

The device should be open and ready for reading the entire document.

See also
setContent()

§ ~QHtmlDocument()

QHtmlDocument::~QHtmlDocument ( )

Destroys the QHtmlDocument.

Warning
Any instances of QHtmlElement associated with this document will become invalid.

Member Function Documentation

§ setContent() [1/2]

bool QHtmlDocument::setContent ( const QString &  content)

Sets the document content to content.

Returns true if the content can be parsed, otherwise false.

Warning
Any instances of QHtmlElement associated with this document will become invalid.

§ setContent() [2/2]

bool QHtmlDocument::setContent ( QIODevice *  device)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Sets the document content to the data contained in device.

The device should be open and ready for reading the entire document.

§ documentElement()

QHtmlElement QHtmlDocument::documentElement ( ) const

Returns the root element of the document.

If the document is null, a null element is returned.

§ htmlElement()

QHtmlElement QHtmlDocument::htmlElement ( ) const

Returns the html element of the document (the element with tag name 'html').

If the document is null, a null element is returned.

§ headElement()

QHtmlElement QHtmlDocument::headElement ( ) const

Returns the head element of the document (the element with tag name 'head').

If the document is null, a null element is returned.

§ bodyElement()

QHtmlElement QHtmlDocument::bodyElement ( ) const

Returns the body element of the document (the element with tag name 'body').

If the document is null, a null element is returned.

§ toString()

QString QHtmlDocument::toString ( ) const

Returns the HTML string of the document.

If the document is null, an empty string is returned.

§ errorString()

QString QHtmlDocument::errorString ( ) const

Returns a description of any error that occurred when parsing the document.

If no error occurred, an empty string is returned.

§ isNull()

bool QHtmlDocument::isNull ( ) const

Returns true if the document is null.

The document is null if no content has been set.


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