Q: best way to parse Gnupg XML

Werner Koch wk at gnupg.org
Wed Jul 4 10:15:01 CEST 2001


 || On Tue, 3 Jul 2001 16:10:50 -0400 (EDT)
 || Bart Trojanowski <bart at jukie.net> wrote: 

 bt> Looks like a steep learning curve.  Is there a better way?

There is also an API to access some of the information more directly:

    algo_buf = g_strdup_printf ("%lu/%s", 
         gpgme_key_get_ulong_attr (key, GPGME_ATTR_LEN, NULL, 0 ),
         gpgme_key_get_string_attr (key, GPGME_ATTR_ALGO, NULL, 0 ) );
    text[COL_ALGO] = algo_buf;

    s = gpgme_key_get_string_attr (key, GPGME_ATTR_KEYID, NULL, 0 );
    if ( strlen (s) == 16 )
        s += 8; /* show only the short keyID */
    text[COL_KEYID] = s;

    s = gpgme_key_get_string_attr (key, GPGME_ATTR_NAME, NULL, 0 );
    text[COL_NAME] = s;

    s = gpgme_key_get_string_attr (key, GPGME_ATTR_EMAIL, NULL, 0 );
    text[COL_EMAIL] = s;

If you want to access the 2nd user ID or key, you have to increment
the last argument like this:

  for (i=0; (s=gpgme_key_get_string_attr (key, GPGME_ATTR_NAME, NULL, i); i++)
        do_something_with (s);

Which interates over all user IDs of the given key.  See gpgme/key.c
for infomration on what attributes you can access.


-- 
Werner Koch        Omnis enim res, quae dando non deficit, dum habetur
g10 Code GmbH      et non datur, nondum habetur, quomodo habenda est.
Privacy Solutions                                        -- Augustinus





More information about the Gnupg-devel mailing list