rubi13133 - 2013-08-03

Hi,

Usage:

To create a new XML use:

    QXmlConfig config;
    config.create();
    ...
    // u can now read/write config
    config.saveAs( filename ); // to save as

To load an existing XML use:

    QXmlConfig config;
    if( config.load( filename ) )
    {
        INFO_LOG( "Xml file opened successfully" );
    }
    else
    {
        ERROR_LOG( QString( "Error opening template xml file: %1, filename=%2" ).arg( 
                       config.getLastErrorMsg() ).arg( filename ) );
        return false;
    }

    ...
    // do what you want and then save 
    config.save();

Textual issues with XML are automatically handled (ok, maybe except for Base64 encoding which is out of the scope of this class)

To read/write XML use:

  1. read/set under current parent element:
    config.set( "name", "value" );
  1. read/set on a file system like path:
    config.cd( "/tree1/tree2" );
    QString value1 = config.getFirst( "object" );
    QString value2 = config.getNext( "object" );
  1. cd/goto to a 'folder' - just as in file system:
    config.cd( "/tree3" ); 
    config.set( "local name", "value" );
  1. use an array "modifier":
    config.set( "/tree3/branch[7]/leaf[3]", value );
or
    // from current parent node
    QString value6 = config.getFirst( "david[5]" ); 
  1. use config.pushCurrentLocation() and config.popCurrentLocation() to push/pop
    current location on the stack. useful when traversing a big configuration file.

  2. You can read/write attributes on the current element.

I guess this class is not 100% complete and tested. Documentation except for this wiki is spartan, yet this is the only (non strict GPL) Xml Config util class available. So, I hope you will find it useful.

GPL alternatives (mine is better! :) )

QXmlSettings @ http://code.google.com/p/qt-dms/

QXmlPutGet @ http://www.workslikeclockwork.com/index.php/components/xml-classes-for-qt/

 

Last edit: rubi13133 2013-08-04