Chapter 2. XML Input/Output
Prev |  | Next

# Chapter 2. XML Input/Output

Saving and restoring your files is done by using XML supporting XPath. The complete persistence layer is described by ags_file.dtd installed on your system. There various classes involved by doing XML IO. It does it in stages as following for reading:

1. Parsing the XML tree and map nodes and objects.
2. Resolving XPath expressions retrieve objects by their nodes.
3. Do as needed callbacks of AgsFileLaunch to setup up the application.

Writing files does ommit the last step. The current AgsConfig is going to be embedded in your file. So you can have per project configuration. Certain objects implement AgsPlugin interface to do an abstraction of reading and writing xmlNode.

## Writing XML files

Writing files is pretty easy. You just have to instantiate AgsFile, set the application context, open it in read-write mode, call ags_file_write() and finally ags_file_close().

Example 2.1. Writing XML

    #include <glib.h>
    #include <glib-object.h>

    #include <ags/libags.h>

    AgsApplicationContext *application_context;
    AgsFile *file;

    GError *error;

    static const gchar *filename = "my_file.xml";

    application_context = ags_application_context_get_instance();

    file = (AgsFile *) g_object_new(AGS_TYPE_FILE,
                                    "application-context", application_context,
                                    "filename", filename,
                                    NULL);

    error = NULL;
    ags_file_rw_open(file,
                     TRUE,
                     &error);
    ags_file_write(file);
    ags_file_close(file);

Prev |  | Next
Common interfaces | Home | Reading XML files