Public Member Functions | Private Member Functions | Private Attributes | List of all members
QXmlInputSource Class Reference

The QXmlInputSource class is the source where XML data is read from. More...

#include <qxml.h>

Public Member Functions

 QXmlInputSource ()
 
 QXmlInputSource (QTextStream &stream)
 
 QXmlInputSource (QFile &file)
 
virtual ~QXmlInputSource ()
 
virtual const QStringdata () const
 
virtual void setData (const QString &d)
 

Private Member Functions

void readInput (QByteArray &rawData)
 

Private Attributes

QString input
 

Detailed Description

The QXmlInputSource class is the source where XML data is read from.

XML

All subclasses of QXmlReader read the input from this class.

Definition at line 162 of file qxml.h.

Constructor & Destructor Documentation

QXmlInputSource::QXmlInputSource ( )

Constructs a input source which contains no data.

Definition at line 725 of file qxml.cpp.

726 {
727  input = "";
728 }
QString input
Definition: qxml.h:176
QXmlInputSource::QXmlInputSource ( QTextStream stream)

Constructs a input source and get the data from the text stream.

Definition at line 733 of file qxml.cpp.

734 {
735  QByteArray rawData;
736  if ( stream.device()->isDirectAccess() ) {
737  rawData = stream.device()->readAll();
738  } else {
739  int nread = 0;
740  const int bufsize = 512;
741  while ( !stream.device()->atEnd() ) {
742  rawData.resize( nread + bufsize );
743  nread += stream.device()->readBlock( rawData.data()+nread, bufsize );
744  }
745  rawData.resize( nread );
746  }
747  readInput( rawData );
748 }
bool resize(uint size)
Definition: qarray.h:69
virtual bool atEnd() const
Definition: qiodevice.cpp:498
virtual int readBlock(char *data, uint maxlen)=0
type * data() const
Definition: qarray.h:63
void readInput(QByteArray &rawData)
Definition: qxml.cpp:784
bool isDirectAccess() const
Definition: qiodevice.h:98
QByteArray readAll()
Definition: qiodevice.cpp:535
QIODevice * device() const
Definition: qtextstream.h:223
QXmlInputSource::QXmlInputSource ( QFile file)

Constructs a input source and get the data from a file. If the file cannot be read the input source is empty.

Definition at line 754 of file qxml.cpp.

755 {
756  if ( !file.open(IO_ReadOnly) ) {
757  input = "";
758  return;
759  }
760  QByteArray rawData = file.readAll();
761  readInput( rawData );
762  file.close();
763 }
#define IO_ReadOnly
Definition: qiodevice.h:61
bool open(int)
Definition: qfile_unix.cpp:134
void readInput(QByteArray &rawData)
Definition: qxml.cpp:784
QByteArray readAll()
Definition: qiodevice.cpp:535
void close()
Definition: qfile_unix.cpp:614
QString input
Definition: qxml.h:176
QXmlInputSource::~QXmlInputSource ( )
virtual

Destructor.

Definition at line 768 of file qxml.cpp.

769 {
770 }

Member Function Documentation

const QString & QXmlInputSource::data ( ) const
virtual

Returns all the data this input source contains.

Definition at line 717 of file qxml.cpp.

718 {
719  return input;
720 }
QString input
Definition: qxml.h:176
void QXmlInputSource::readInput ( QByteArray rawData)
private

Read the XML file from the byte array; try to recoginize the encoding.

Definition at line 784 of file qxml.cpp.

785 {
786  QBuffer buf( rawData );
787  buf.open( IO_ReadOnly );
788  QTextStream *stream = new QTextStream( &buf );
789  QChar tmp;
790  // assume UTF8 or UTF16 at first
792  input = "";
793  // read the first 5 characters
794  for ( int i=0; i<5; i++ ) {
795  *stream >> tmp;
796  input += tmp;
797  }
798  // starts the document with an XML declaration?
799  if ( input == "<?xml" ) {
800  // read the whole XML declaration
801  do {
802  *stream >> tmp;
803  input += tmp;
804  } while( tmp != '>' );
805  // and try to find out if there is an encoding
806  int pos = input.find( "encoding" );
807  if ( pos != -1 ) {
809  do {
810  pos++;
811  if ( pos > (int)input.length() )
812  goto finished;
813  } while( input[pos] != '"' && input[pos] != '\'' );
814  pos++;
815  while( input[pos] != '"' && input[pos] != '\'' ) {
816  encoding += input[pos];
817  pos++;
818  if ( pos > (int)input.length() )
819  goto finished;
820  }
821  delete stream;
822  stream = new QTextStream( &buf );
823  stream->setCodec( QTextCodec::codecForName( encoding.utf8() ) );
824  buf.reset();
825  input = "";
826  }
827  }
828 finished:
829  input += stream->read();
830  delete stream;
831  buf.close();
832 }
void setCodec(QTextCodec *)
void setEncoding(Encoding)
The QBuffer class is an I/O device that operates on a QByteArray.
Definition: qbuffer.h:47
The QString class provides an abstraction of Unicode text and the classic C null-terminated char arra...
Definition: qstring.h:350
The QChar class provides a light-weight Unicode character.
Definition: qstring.h:56
#define IO_ReadOnly
Definition: qiodevice.h:61
uint length() const
Definition: qstring.h:679
string tmp
Definition: languages.py:63
QString read()
The QTextStream class provides basic functions for reading and writing text using a QIODevice...
Definition: qtextstream.h:53
static QTextCodec * codecForName(const char *hint, int accuracy=0)
Definition: qtextcodec.cpp:626
int find(QChar c, int index=0, bool cs=TRUE) const
Definition: qstring.cpp:12902
static QCString encoding
Definition: config.cpp:1052
QCString utf8() const
Definition: qstring.cpp:14507
QString input
Definition: qxml.h:176
void QXmlInputSource::setData ( const QString dat)
virtual

Sets the data of the input source to dat.

Definition at line 775 of file qxml.cpp.

776 {
777  input = dat;
778 }
QString input
Definition: qxml.h:176

Member Data Documentation

QString QXmlInputSource::input
private

Definition at line 176 of file qxml.h.


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