Home · All Classes · All Functions
Public Functions

QXmlGet Class Reference

Public Functions

 QXmlGet ()
 QXmlGet (QDomDocument document)
 QXmlGet (const QXmlPut &xmlPut)
QDomDocument document () const
QString docType () const
QString publicId () const
QString systemId () const
QString xmlDeclaration () const
QString xmlVersion () const
QString encoding () const
bool standalone () const
bool find (const QString &tagName)
bool findAndDescend (const QString &tagName)
void findReset ()
bool findNext (const QString &tagName=QString())
bool findNextAndDescend (const QString &tagName=QString())
int childCount (const QString &tagName=QString()) const
bool hasChildren () const
QString tagName () const
QString getString (const QString &defaultValue=QString()) const
QStringList getStringList (const QStringList &defaultValue=QStringList())
int getInt (int defaultValue=0) const
QVector< int > getIntVector (const QVector< int > &defaultValue=QVector< int >()) const
double getDouble (double defaultValue=0) const
QVector< double > getDoubleVector (const QVector< double > &defaultValue=QVector< double >()) const
bool getBool (bool defaultValue=false, QXmlPutGet::BoolFormats formats=QXmlPutGet::bfAll) const
QVector< bool > getBoolVector (const QVector< bool > &defaultValue=QVector< bool >(), QXmlPutGet::BoolFormats formats=QXmlPutGet::bfAll) const
QColor getColor (const QColor &defaultValue=QColor()) const
QSize getSize (const QSize &defaultValue=QSize()) const
QSizeF getSizeF (const QSizeF &defaultValue=QSizeF()) const
QPoint getPoint (const QPoint &defaultValue=QPoint()) const
QPointF getPointF (const QPointF &defaultValue=QPointF()) const
QRect getRect (const QRect &defaultValue=QRect()) const
QRectF getRectF (const QRectF &defaultValue=QRectF()) const
QDate getDate (const QDate &defaultValue=QDate()) const
QTime getTime (const QTime &defaultValue=QTime()) const
QDateTime getDateTime (const QDateTime &defaultValue=QDateTime()) const
QByteArray getByteArray (const QByteArray &defaultValue=QByteArray()) const
QImage getImage (const QImage &defaultValue=QImage()) const
QPen getPen (const QPen &defaultValue=QPen()) const
QBrush getBrush (const QBrush &defaultValue=QBrush()) const
QFont getFont (const QFont &defaultValue=QFont()) const
bool hasAttribute (const QString &name) const
QString getAttributeString (const QString &name, const QString &defaultValue=QString()) const
int getAttributeInt (const QString &name, int defaultValue=0) const
QVector< int > getAttributeIntVector (const QString &name, const QVector< int > &defaultValue=QVector< int >()) const
double getAttributeDouble (const QString &name, double defaultValue=0) const
QVector< double > getAttributeDoubleVector (const QString &name, const QVector< double > &defaultValue=QVector< double >()) const
bool getAttributeBool (const QString &name, bool defaultValue=false, QXmlPutGet::BoolFormats formats=QXmlPutGet::bfAll) const
QVector< bool > getAttributeBoolVector (const QString &name, const QVector< bool > &defaultValue=QVector< bool >(), QXmlPutGet::BoolFormats format=QXmlPutGet::bfAll) const
QColor getAttributeColor (const QString &name, const QColor &defaultValue=QColor()) const
bool fromString (const QString &str, QString *errorMessage=0, int *errorLine=0, int *errorColumn=0)
bool load (const QString &fileName, QString *errorMessage=0, int *errorLine=0, int *errorColumn=0)
QXmlGet restricted ()
void descend ()
QXmlGet descended ()
bool rise ()
bool goTo (QDomElement parentElement)
QDomElement element () const

Constructor & Destructor Documentation

QXmlGet::QXmlGet ( )

Creates a QXmlGet instance with an empty document. Call fromString or load to conveniently load XML content to the document. If you have a QDomDocument ready, use the QXmlGet(QDomDocument document) constructor instead.

QXmlGet::QXmlGet ( QDomDocument  document)

This is an overloaded function.

Creates a QXmlGet instance from the passed QDomDocument. This instance can then read from the document.

QXmlGet::QXmlGet ( const QXmlPut xmlPut)

This is an overloaded function.

Creates a QXmlGet instance from the QXmlPut instance xmlPut. This way you may now read from the document, to which the QXmlPut instance writes.


Member Function Documentation

QDomDocument QXmlGet::document ( ) const [inline]

Returns the QDomDocument this QXmlGet instance is using.

QString QXmlGet::docType ( ) const

Returns the doctype name.

example:

  <?xml version="1.0" encoding="UTF-8"?>
  <!DOCTYPE myDocType PUBLIC 'myPublicId' 'mySystemId'>
  <root>
    (...)
  </root>

has the doctype "myDocType".

QString QXmlGet::publicId ( ) const

Returns the public identifier of the external DTD subset or an empty string if there is no public identifier.

example:

  <?xml version="1.0" encoding="UTF-8"?>
  <!DOCTYPE myDocType PUBLIC 'myPublicId' 'mySystemId'>
  <root>
    (...)
  </root>

has the public identifier "myPublicId".

QString QXmlGet::systemId ( ) const

Returns the system identifier of the external DTD subset or an empty string if there is no system identifier.

example:

  <?xml version="1.0" encoding="UTF-8"?>
  <!DOCTYPE myDocType PUBLIC 'myPublicId' 'mySystemId'>
  <root>
    (...)
  </root>

has the system identifier "mySystemId".

QString QXmlGet::xmlDeclaration ( ) const [inline]

Returns the XML-Declaration (the tag name of the <? .. ?> header), which always is "xml".

(Thus this function is rather redundant, but the DOM provides it, so it is provided here, too.)

QString QXmlGet::xmlVersion ( ) const [inline]

Returns the xml version of the document. Typically this is "1.0" or "1.1".

example:

  <?xml version="1.0" encoding="UTF-8"?>
  (...)
QString QXmlGet::encoding ( ) const [inline]

Returns the encoding of the document, e.g. "UTF-8".

example:

  <?xml version="1.0" encoding="UTF-8"?>
  (...)
bool QXmlGet::standalone ( ) const [inline]

Returns the standalone-property of the document's xml declaration.

example:

  <?xml version="1.0" encoding="UTF-8"?>

has standalone false

  <?xml version="1.0" encoding="UTF-8" standalone="yes"?>

has standalone true.

bool QXmlGet::find ( const QString &  tagName)

Finds the first element named tagName in the current hierarchy level. If this returns true, an element was found. You then can access contents and attributes of this element via the get(...) functions.

For example, if you expect the element to contain a string as in

<element>Hellothere!</element>

call getString to retrieve "Hello there!".

If you expect the element to have further child elements and want to descend into their hierarchy level, call descend or descended.

If you expect more than one element with the name tagName in the current hierarchy level, consider using findNext instead, because find would always just find the first element.

See also:
findNext, findAndDescend, findNextAndDescend, findReset
bool QXmlGet::findAndDescend ( const QString &  tagName)

Finds the first element with the specified tagName in the current hierarchy level and (if found) descends into it. If such an element is found, the function returns true. In that case you must make sure to call rise after the work in the lower hierarchy level is done.

If you expect more than one element with the name tagName in the current hierarchy level, consider using findNextAndDescend instead, because findAndDescend would always just find the first element.

See also:
findNextAndDescend, find, descend, descended
void QXmlGet::findReset ( )

Resets the current element to the starting position (this means it will be pointing to the parent of the current hierarchy level). Any subsequent call to findNext or findNextAndDescend would start searching from the beginning. Calls to find are not affected, since it always starts searching from the beginning.

See also:
findNext, findNextAndDescend, find
bool QXmlGet::findNext ( const QString &  tagName = QString())

finds the next element after the current element with tag name tagName.

Returns true when an element was found. This makes it possible to use it directly as a condition of a while-loop, looping over all elements with name tagName. If you want to descend into every such element, consider using findNextAndDescend.

Once no next element was found, the function returns false and the current element is reset. This means a subsequent call would restart the loop from the beginning, for example searching for a different tagName.

See also:
findReset, findNextAndDescend, find
bool QXmlGet::findNextAndDescend ( const QString &  tagName = QString())

finds the next element after the current element with tag name tagName and descends into it.

Returns true when an element was found. This makes it possible to use it directly as a condition of a while-loop, looping over (and descending into) all elements with name tagName. Don't forget to call rise at the end of each iteration.

Once no next element was found, the function returns false and the current element is reset. This means a subsequent call would restart the loop from the beginning, for example searching for a different tagName.

See also:
findNext, findReset, find
int QXmlGet::childCount ( const QString &  tagName = QString()) const

Returns the number of elements with the specified tag name inside the current element. If tagName is empty, all elements are counted.

See also:
hasChildren
bool QXmlGet::hasChildren ( ) const

Returns whether the current element has children (sub elements). If so, you can call descend or descended to change into their hierarchy level to access them.

See also:
childCount
QString QXmlGet::tagName ( ) const

Returns the tag name of the current element.

For example, the element

<rect width="4">

has the tag name "rect".

QString QXmlGet::getString ( const QString &  defaultValue = QString()) const

Returns the string the current tag contains. If the current tag doesn't contain a string, defaultValue is returned.

See also:
getStringList
QStringList QXmlGet::getStringList ( const QStringList &  defaultValue = QStringList())

Returns the string list the current tag contains. If the current tag doesn't contain a string list, defaultValue is returned.

See also:
getString
int QXmlGet::getInt ( int  defaultValue = 0) const

Returns the integer the current tag contains. If the current tag doesn't contain an integer, defaultValue is returned.

See also:
getIntVector
QVector< int > QXmlGet::getIntVector ( const QVector< int > &  defaultValue = QVector<int>()) const

Returns the integer vector the current tag contains. If the current tag doesn't contain an integer vector, defaultValue is returned.

See also:
getInt
double QXmlGet::getDouble ( double  defaultValue = 0) const

Returns the double the current tag contains. If the current tag doesn't contain a double, defaultValue is returned.

See also:
getDoubleVector
QVector< double > QXmlGet::getDoubleVector ( const QVector< double > &  defaultValue = QVector<double>()) const

Returns the double vector the current tag contains. If the current tag doesn't contain a double vector, defaultValue is returned.

See also:
getDouble
bool QXmlGet::getBool ( bool  defaultValue = false,
QXmlPutGet::BoolFormats  formats = QXmlPutGet::bfAll 
) const

Returns the bool the current tag contains. If the current tag doesn't contain a bool, defaultValue is returned.

by setting formats, you may specify which boolean formats this function accepts.

See also:
getBoolVector, QXmlPutGet::BoolFormat
QVector< bool > QXmlGet::getBoolVector ( const QVector< bool > &  defaultValue = QVector<bool>(),
QXmlPutGet::BoolFormats  formats = QXmlPutGet::bfAll 
) const

Returns the bool vector the current tag contains. If the current tag doesn't contain a bool vector, defaultValue is returned.

by setting formats, you may specify which boolean formats this function accepts.

See also:
getBool, QXmlPutGet::BoolFormat
QColor QXmlGet::getColor ( const QColor &  defaultValue = QColor()) const

Returns the QColor the current tag contains. If the current tag doesn't contain a QColor, defaultValue is returned.

QSize QXmlGet::getSize ( const QSize &  defaultValue = QSize()) const

Returns the QSize the current tag contains. If the current tag doesn't contain a QSize, defaultValue is returned.

See also:
getSizeF
QSizeF QXmlGet::getSizeF ( const QSizeF &  defaultValue = QSizeF()) const

Returns the QSizeF the current tag contains. If the current tag doesn't contain a QSizeF, defaultValue is returned.

See also:
getSize
QPoint QXmlGet::getPoint ( const QPoint &  defaultValue = QPoint()) const

Returns the QPoint the current tag contains. If the current tag doesn't contain a QPoint, defaultValue is returned.

See also:
getPointF
QPointF QXmlGet::getPointF ( const QPointF &  defaultValue = QPointF()) const

Returns the QPointF the current tag contains. If the current tag doesn't contain a QPointF, defaultValue is returned.

See also:
getPoint
QRect QXmlGet::getRect ( const QRect &  defaultValue = QRect()) const

Returns the QRect the current tag contains. If the current tag doesn't contain a QRect, defaultValue is returned.

See also:
getRectF
QRectF QXmlGet::getRectF ( const QRectF &  defaultValue = QRectF()) const

Returns the QRectF the current tag contains. If the current tag doesn't contain a QRectF, defaultValue is returned.

See also:
getRect
QDate QXmlGet::getDate ( const QDate &  defaultValue = QDate()) const

Returns the QDate the current tag contains. If the current tag doesn't contain a QDate, defaultValue is returned.

See also:
getDateTime, getTime
QTime QXmlGet::getTime ( const QTime &  defaultValue = QTime()) const

Returns the QTime the current tag contains. If the current tag doesn't contain a QTime, defaultValue is returned.

See also:
getDateTime, getDate
QDateTime QXmlGet::getDateTime ( const QDateTime &  defaultValue = QDateTime()) const

Returns the QDateTime the current tag contains. If the current tag doesn't contain a QDateTime, defaultValue is returned.

See also:
getTime, getDate
QByteArray QXmlGet::getByteArray ( const QByteArray &  defaultValue = QByteArray()) const

Returns the QByteArray the current tag contains. If the current tag doesn't contain a QByteArray, defaultValue is returned.

QImage QXmlGet::getImage ( const QImage &  defaultValue = QImage()) const

Returns the QImage the current tag contains. If the current tag doesn't contain a QImage, defaultValue is returned.

QPen QXmlGet::getPen ( const QPen &  defaultValue = QPen()) const

Returns the QPen the current tag contains. If the current tag doesn't contain a QPen, defaultValue is returned.

See also:
getBrush
QBrush QXmlGet::getBrush ( const QBrush &  defaultValue = QBrush()) const

Returns the QBrush the current tag contains. If the current tag doesn't contain a QBrush, defaultValue is returned.

See also:
getPen
QFont QXmlGet::getFont ( const QFont &  defaultValue = QFont()) const

Returns the QFont the current tag contains. If the current tag doesn't contain a QFont, defaultValue is returned.

bool QXmlGet::hasAttribute ( const QString &  name) const

Returns whether the current tag has an attribute with the name name.

QString QXmlGet::getAttributeString ( const QString &  name,
const QString &  defaultValue = QString() 
) const

Returns the string the current tag carries as attribute with the name name. If the current tag doesn't contain such an attribute,defaultValue is returned.

int QXmlGet::getAttributeInt ( const QString &  name,
int  defaultValue = 0 
) const

Returns the integer the current tag carries as attribute with the name name. If the current tag doesn't contain such an attribute,defaultValue is returned.

See also:
getAttributeIntVector
QVector< int > QXmlGet::getAttributeIntVector ( const QString &  name,
const QVector< int > &  defaultValue = QVector<int>() 
) const

Returns the integer vector the current tag carries as attribute with the name name. If the current tag doesn't contain such an attribute,defaultValue is returned.

See also:
getAttributeInt
double QXmlGet::getAttributeDouble ( const QString &  name,
double  defaultValue = 0 
) const

Returns the double the current tag carries as attribute with the name name. If the current tag doesn't contain such an attribute,defaultValue is returned.

See also:
getAttributeDoubleVector
QVector< double > QXmlGet::getAttributeDoubleVector ( const QString &  name,
const QVector< double > &  defaultValue = QVector<double>() 
) const

Returns the double vector the current tag carries as attribute with the name name. If the current tag doesn't contain such an attribute,defaultValue is returned.

See also:
getAttributeDouble
bool QXmlGet::getAttributeBool ( const QString &  name,
bool  defaultValue = false,
QXmlPutGet::BoolFormats  formats = QXmlPutGet::bfAll 
) const

Returns the bool the current tag carries as attribute with the name name. If the current tag doesn't contain such an attribute,defaultValue is returned.

by setting formats, you may specify which boolean formats this function accepts.

See also:
getAttributeBoolVector
QVector< bool > QXmlGet::getAttributeBoolVector ( const QString &  name,
const QVector< bool > &  defaultValue = QVector<bool>(),
QXmlPutGet::BoolFormats  formats = QXmlPutGet::bfAll 
) const

Returns the bool vector the current tag carries as attribute with the name name. If the current tag doesn't contain such an attribute,defaultValue is returned.

by setting formats, you may specify which boolean formats this function accepts.

See also:
getAttributeBool
QColor QXmlGet::getAttributeColor ( const QString &  name,
const QColor &  defaultValue = QColor() 
) const

Returns the QColor the current tag carries as attribute with the name name. If the current tag doesn't contain such an attribute,defaultValue is returned.

bool QXmlGet::fromString ( const QString &  str,
QString *  errorMessage = 0,
int *  errorLine = 0,
int *  errorColumn = 0 
)

Loads the XML content from the string str into this QXmlGet instance. Returns true on success.

If the provided markup contains errors, this function returns false and outputs the error message in errorMessage and the location of the error in errorLine and errorColumn.

See also:
QXmlPut::toString
bool QXmlGet::load ( const QString &  fileName,
QString *  errorMessage = 0,
int *  errorLine = 0,
int *  errorColumn = 0 
)

Loads the XML content from the file fileName into this QXmlGet instance. Returns true on success.

If the provided markup contains errors, this function returns false and outputs the error message in errorMessage and the location of the error in errorLine and errorColumn.

If the provided file can't be opened (e.g. because it doesn't exist or the application doesn't have read permission), this function returns false and errorMessage, errorLine and errorColumn are left unchanged.

See also:
QXmlPut::save
QXmlGet QXmlGet::restricted ( )

Returns a QXmlGet instance on the same Document and at the same position as this instance, but which is restricted to this hierarchy level (and the levels below). This means, the returned QXmlGet instance isn't allowed to rise above the current hierarchy level.

This is useful if you wish that subroutines can handle their own XML work without possibly interfering with the rest. By passing a restricted instance, it's guaranteed the subroutines don't accidentally write/read outside their designated XML element.

If only the subroutine needs to write to/read from a specific element, consider using descended.

example:

  if (xmlGet.find("toptag")) // we might have better used findAndDescend() here.
  {
    xmlGet.descend();
    if (xmlGet.find("stringtag"))
      QString str = xmlGet.getString();
    readOtherContent(xmlGet.restricted()); // A subroutine that reads from the <toptag> level
    xmlGet.rise();
  }
See also:
descended
void QXmlGet::descend ( )

Descends into the current element. Child elements can then be accessed normally via find etc.

Once the work in the lower hierarchy level is done, you can return to the previous position in the parent hierarchy level by calling rise.

If a subroutine needs to write to/read from a specific element, consider using descended instead of a descend-rise-pair.

example:

  if (xmlGet.find("firsttag")) // we might have better used findAndDescend() here.
  {
    xmlGet.descend(); // descend into the <firsttag> element, it is now the parent element.
    if (xmlGet.find("stringtag"))
      QString str = xmlGet.getString();
    xmlGet.rise(); // rise from the <firsttag> element. <firsttag> is now the current element again, and not the parent element anymore.
  }
See also:
rise, descended, findAndDescend, findNextAndDescend
QXmlGet QXmlGet::descended ( )

Returns a QXmlGet instance that is descended into and restricted to the current element. Child elements can then be accessed with the returned instance normally via find etc.

Due to the restriction, the returned instance can't rise above its initial hierarchy level, i.e. into or above the hierarchy level of the instance this function is called on.

When descending into elements like this, there is no need to call rise (and thus no possibility to forget a rise), because the current instance isn't influenced. Whatever descending/rising the subroutine does with the returned instance can't break the callers XML handling code.

example:

  if (xmlGet.find("header"))
    readHeaderSubroutine(xmlGet.descended());
  if (xmlGet.find("body"))
    readBodySubroutine(xmlGet.descended());
  if (xmlGet.find("footer"))
    readFooterSubroutine(xmlGet.descended());
See also:
restricted, descend
bool QXmlGet::rise ( )

Rises to the previous position in the parent hierarchy level. This finishes the work in a lower hierarchy level that was started with descend earlier.

If a subroutine needs to write to/read from a specific element, consider using descended instead of a descend-rise-pair.

If this instance is restricted (see descended and restricted) and is already inside its highest allowed hierarchy level, a further attempt to rise will return false without changing the current hierarchy level, and cause a corresponding qDebug output.

example:

  if (xmlGet.find("firsttag")) // we might have better used findAndDescend() here.
  {
    xmlGet.descend(); // descend into the <firsttag> element, it is now the parent element.
    if (xmlGet.find("stringtag"))
      QString str = xmlGet.getString();
    xmlGet.rise(); // rise from the <firsttag> element. <firsttag> is now the current element again, and not the parent element anymore.
  }
See also:
descend
bool QXmlGet::goTo ( QDomElement  parentElement)

Changes the current parent element to parentElement. It must be in the current QDomDocument already.

If this instance is restricted (see descended and restricted) and parentElement is not inside the allowed hierarchy, this function will return false without changing the current position, and cause a corresponding qDebug output.

You probably won't use this function very often, since normal, linear QXmlPutGet navigation should be done with find, descend, rise, descended, etc. However, it's useful for nonlinear XML navigation, where frequent jumps between different locations in the XML hierarchy need to be done.

See also:
element
QDomElement QXmlGet::element ( ) const [inline]

Returns the current element as a QDomElement. This can be used as a jump target for goTo, or some low-level manipulation of the node with the Qt-DOM-interface.


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