Classes - Annotated - Tree - Functions - Home - Structure

QXmlInputSource Class Reference
[XML module]

The QXmlInputSource class provides the input data for the QXmlReader subclasses. More...

#include <qxml.h>

List of all member functions.

Public Members

Protected Members


Detailed Description

The QXmlInputSource class provides the input data for the QXmlReader subclasses.

All subclasses of QXmlReader read the input XML document from this class.

This class recognizes the encoding of the data: it tries to read the encoding declaration of the XML file and if it finds it, it reads the data in the corresponding encoding. If it does not find an encoding declaration, then it assumes that the data is either in UTF-8 or UTF-16, depending if it can find a byte-order mark.

There are two ways to populate the input source with data: you can construct it with a QIODevice* and the input source reads the data from that device. Or you can set the data explicitly with one of the setData() functions.

Usually you either construct a QXmlInputSource that works on a QIODevice* or you construct an empty QXmlInputSource and set the data with setData(). There are only rare occasions where you want to mix both methods.

The subclasses of QXmlReader use the next() function to read the input character by character. So the input source behaves like a stream. If you want to start from the beginning again, you have to call reset() to change the position in the input source to the beginning.

The functions data() and fetchData() are useful if you want to do also something else with data than parsing, e.g. displaying the raw XML file - the advantage to do this job with the QXmlInputClass is, that it tries to recognize the right encoding.

See also QXmlReader and QXmlSimpleReader.


Member Function Documentation

QXmlInputSource::QXmlInputSource ()

Constructs an input source which contains no data.

See also setData().

QXmlInputSource::QXmlInputSource ( QIODevice * dev )

Constructs an input source and gets the data from dev. If dev is not open, it is opened in read-only mode. If dev is a null pointer or it is not possible to read from the device, the input source will contain no data.

See also setData(), fetchData() and QIODevice.

QXmlInputSource::QXmlInputSource ( QFile & file )

This function is obsolete. It is provided to keep old source working. We strongly advise against using it in new code.

Constructs an input source and gets the data from the file file. If the file cannot be read the input source is empty.

QXmlInputSource::QXmlInputSource ( QTextStream & stream )

This function is obsolete. It is provided to keep old source working. We strongly advise against using it in new code.

Constructs an input source and gets the data from the text stream stream.

QXmlInputSource::~QXmlInputSource () [virtual]

Destructor.

QString QXmlInputSource::data () [virtual]

Returns the data the input source contains or QString::null if the input source does not contain any data.

See also setData(), QXmlInputSource() and fetchData().

void QXmlInputSource::fetchData () [virtual]

This function reads more data from the device that was given on construction. If the input source already contained data, this function deletes that data first.

This class contains no data after a call to this function, if either the class was constructed without a device to read data from or if this function was not able to get more data from the device.

Please note that there are two occasions where a fetch is done implicitly by another function call: This class does a fetch itself on construction. So you shouldn't call a fetchData() right afterwards since you loose all that data. Furthermore, a call to next() can also implicitly call fetchData(). So this function should be used with care.

See also data(), next() and QXmlInputSource().

QString QXmlInputSource::fromRawData ( const QByteArray & data, bool beginning = FALSE ) [virtual protected]

This function reads the XML file from data and tries to recoginize the encoding. It converts the raw data data to a QString and returns it. It tries the best to get the right encoding for the XML file.

If beginning is TRUE, this function assumes the beginning of a new XML document and looks for a new encoding declaration. If beginning is FALSE, it converts the raw data with the guess from prior calls. Specifying FALSE is useful if you do incremental parsing, i.e., when one XML document is parsed in chunks.

QChar QXmlInputSource::next () [virtual]

Returns the next character of the input source. If this funciton reaches the end of available data, it returns QXmlInputSource::EndOfData. If you call next() after that, it tries to fetch more data by calling fetchData(). If this call results in new data, this function returns the first character of that data; otherwise it returns QXmlInputSource::EndOfDocument.

This function can have the two special return values QXmlInputSource::EndOfData and QXmlInputSource::EndOfDocument. This destinction is useful for incremental parsing: QXmlInputSource::EndOfData means that the input source ran out of data, but may be able to deliver more data at a later point. QXmlInputSource::EndOfDocument on the other hand means, that the input source really ran out of data and can't provide more data at a later point. The non-incremental parsing mode does not distinguish between the two values - they mean that the end of the data was reached.

See also reset(), fetchData(), QXmlSimpleReader::prarse() and QXmlSimpleReader::parseContinue().

void QXmlInputSource::reset () [virtual]

This function sets the position used by next() to the beginning of the data returned by data(). This is useful if you want to use the input source for more than one parse.

See also next().

Example: xml/tagreader-with-features/tagreader.cpp.

void QXmlInputSource::setData ( const QString & dat ) [virtual]

Sets the data of the input source to dat.

If the input source already contains data, this function deletes that data first.

See also data().

void QXmlInputSource::setData ( const QByteArray & dat ) [virtual]

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

The data dat is sent through the right text-codec first, before it is set.


Search the documentation, FAQ, qt-interest archive and more (uses www.trolltech.com):


This file is part of the Qt toolkit, copyright © 1995-2001 Trolltech, all rights reserved.


Copyright © 2001 TrolltechTrademarks
Qt version 3.0.0-beta1-beta1