Re: Code for placing a XML dock in a GtkTree?



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

G Hasse wrote:
| Hello,
|
| To place an XML document in a GtkTree must be a fairly common
| stuff to do. Can anyone point me to some examples or code I would
| be happy.
|

Basically you use something like an XML_Parser (from http://www.libexpat.org/), you're
distro may have the "expat" package, well, you'll need expat-devel, and #include <expat.h>)

XML_Parser is setup with callback routines that are passed the xml tag, and associated data.

The XML_Parser object is then used to parse the xml blob, and it will call callback
routines at each xml level.

The callback routine then decides what to do with the tag (and associated date). It might,
for example, create a new row in the GtkTree, or it might create a new node, or it might
ignore the data altogether.

Setting up the parser might be something as simple as this:


int parse_xml_rooms(char *mybuff, int bytes_read, int is_category) {
~        XML_Parser p;
~        void *buff;
~        p = XML_ParserCreate(NULL);      /* XML_ParserCreate( "iso-8859-1"); */
~        if (is_category) {XML_SetElementHandler(p, callback_start_cat, callback_end_cat);}
~        else {XML_SetElementHandler(p, callback_start_rooms, callback_end_rooms);}
~        XML_SetCharacterDataHandler(p, callback_cdata);
~        XML_SetUnknownEncodingHandler(p, callback_enc, NULL);
~        XML_SetUserData(p, "");

~        buff = XML_GetBuffer(p, bytes_read+3);
~        if (buff == NULL) {
~                return -1;
~        }

~        strncpy((char *)buff,mybuff,bytes_read+1);

~        if (! XML_ParseBuffer(p, bytes_read, bytes_read == 0)) {
~                return 1;
~        }

~        XML_ParserFree(p);
~        return 1;

The work of creating the tree rows is done in the callback routine, based upon the xml path.

A working example can be found here:

        http://gyachi.cvs.sourceforge.net/gyachi/gyachi/client/roomlist.c?view=log

This creates the room list UI in the GyachI yahoo messenger program.

:)

All the best,

- -Greg


- --
+---------------------------------------------------------------------+

Please also check the log file at "/dev/null" for additional information.
                (from /var/log/Xorg.setup.log)

| Greg Hosler                                   ghosler redhat com    |
+---------------------------------------------------------------------+
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)

iD8DBQFITnsY404fl/0CV/QRAlxoAJ9IhHPZHokL3QMHd95Mfccaajf7ogCguK23
TqFk8T/GQY0/FSksSTiHLbQ=
=h5ue
-----END PGP SIGNATURE-----



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]