Movatterモバイル変換


[0]ホーム

URL:


We bake cookies in your browser for a better experience. Using this site means that you consent.Read More

Menu

Qt Documentation

QXmlInputSource Class

TheQXmlInputSource class provides the input data for theQXmlReader subclasses.More...

Header:#include <QXmlInputSource>

Note: All functions in this class arereentrant.

Public Functions

QXmlInputSource()
QXmlInputSource(QIODevice * dev)
virtual~QXmlInputSource()
virtual QStringdata() const
virtual voidfetchData()
virtual QCharnext()
virtual voidreset()
virtual voidsetData(const QString & dat)
virtual voidsetData(const QByteArray & dat)

Protected Functions

virtual QStringfromRawData(const QByteArray & data, bool beginning = false)

Detailed Description

TheQXmlInputSource class provides the input data for theQXmlReader subclasses.

All subclasses ofQXmlReader read the input XML document from this class.

This class recognizes the encoding of the data by reading the encoding declaration in the XML file if it finds one, and reading the data using 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 on whether it can find a byte-order mark.

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

Usually you either construct aQXmlInputSource that works on aQIODevice* or you construct an emptyQXmlInputSource and set the data withsetData(). There are only rare occasions where you would want to mix both methods.

TheQXmlReader subclasses use thenext() function to read the input character by character. If you want to start from the beginning again, usereset().

The functionsdata() andfetchData() are useful if you want to do something with the data other than parsing, e.g. displaying the raw XML file. The benefit of using the QXmlInputClass in such cases is that it tries to use the correct encoding.

See alsoQXmlReader andQXmlSimpleReader.

Member Function Documentation

QXmlInputSource::QXmlInputSource()

Constructs an input source which contains no data.

See alsosetData().

QXmlInputSource::QXmlInputSource(QIODevice * dev)

Constructs an input source and gets the data from devicedev. Ifdev is not open, it is opened in read-only mode. Ifdev is 0 or it is not possible to read from the device, the input source will contain no data.

See alsosetData(),fetchData(), andQIODevice.

[virtual]QXmlInputSource::~QXmlInputSource()

Destructor.

[virtual]QString QXmlInputSource::data() const

Returns the data the input source contains or an empty string if the input source does not contain any data.

See alsosetData(),QXmlInputSource(), andfetchData().

[virtual]void QXmlInputSource::fetchData()

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

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

There are two occasions where a fetch is done implicitly by another function call: during construction (so that the object starts out with some initial data where available), and during a call tonext() (if the data had run out).

You don't normally need to use this function if you usenext().

See alsodata(),next(), andQXmlInputSource().

[virtual protected]QString QXmlInputSource::fromRawData(constQByteArray & data,bool beginning = false)

This function reads the XML file fromdata and tries to recognize the encoding. It converts the raw datadata into aQString and returns it. It tries its best to get the correct encoding for the XML file.

Ifbeginning is true, this function assumes that the data starts at the beginning of a new XML document and looks for an encoding declaration. Ifbeginning is false, it converts the raw data using the encoding determined from prior calls.

[virtual]QChar QXmlInputSource::next()

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

Readers, such asQXmlSimpleReader, will assume that the end of the XML document has been reached if the this function returnsQXmlInputSource::EndOfDocument, and will check that the supplied input is well-formed. Therefore, when reimplementing this function, it is important to ensure that this behavior is duplicated.

See alsoreset(),fetchData(),QXmlSimpleReader::parse(), andQXmlSimpleReader::parseContinue().

[virtual]void QXmlInputSource::reset()

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

Note:In the case that the underlying data source is aQIODevice, the current position in the device is not automatically set to the start of input. CallQIODevice::seek(0) on the device to do this.

See alsonext().

[virtual]void QXmlInputSource::setData(constQString & dat)

Sets the data of the input source todat.

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

See alsodata().

[virtual]void QXmlInputSource::setData(constQByteArray & dat)

This is an overloaded function.

The datadat is passed through the correct text-codec, before it is set.

© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.


[8]ページ先頭

©2009-2025 Movatter.jp