[Libosinfo] [PATCH v2 4/4] osinfo_loader: do not use xpath to read localized strings

Daniel P. Berrange berrange at redhat.com
Thu Jun 5 10:49:43 UTC 2014


On Tue, Jun 03, 2014 at 08:19:04PM +0200, Giuseppe Scrivano wrote:
> Signed-off-by: Giuseppe Scrivano <gscrivan at redhat.com>
> ---
>  osinfo/osinfo_loader.c | 26 +++++++++++++++-----------
>  1 file changed, 15 insertions(+), 11 deletions(-)
> 
> diff --git a/osinfo/osinfo_loader.c b/osinfo/osinfo_loader.c
> index 6e79e78..6fe7145 100644
> --- a/osinfo/osinfo_loader.c
> +++ b/osinfo/osinfo_loader.c
> @@ -328,17 +328,21 @@ static void osinfo_loader_entity(OsinfoLoader *loader,
>           * want to ignore that, hence the NULL check on index 'j + 1'.
>           */
>          if (keys[i].type == G_TYPE_STRING) {
> -            for (j = 0; langs[j + 1] != NULL; j++) {
> -                xpath = g_strdup_printf("string(./%s[lang('%s')])",
> -                                        keys[i].name, langs[j]);
> -                value_str = osinfo_loader_string(xpath, loader, ctxt, err);
> -                g_free(xpath);
> -                xpath = NULL;
> -                if (error_is_set(err))
> -                    return;
> -
> -                if (value_str != NULL)
> -                    break;
> +            xmlNodePtr it;
> +            for (it = root->children; it; it = it->next) {
> +                if (xmlStrEqual(it->name, BAD_CAST keys[i].name)) {
> +                    xmlChar *lang = xmlGetProp(it, BAD_CAST "lang");
> +                    if (lang == NULL)
> +                        continue;
> +
> +                    for (j = 0; langs[j + 1] != NULL; j++) {
> +                        if (xmlStrEqual(lang, BAD_CAST langs[j])) {
> +                            gchar *content = (gchar *) it->children->content;
> +                            value_str = g_strdup(content);
> +                            break;
> +                        }
> +                    }
> +                }
>              }
>          }

ACK

Regards,
Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|




More information about the Libosinfo mailing list