From: Pavel Charvat Date: Thu, 24 Apr 2008 07:32:58 +0000 (+0200) Subject: XML: implemented user-friendly function to deal with default attribute values X-Git-Tag: holmes-import~449^2~6 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=ccd6cdc3fe59f222ed3c4515fa9c4065479f6d9d;p=libucw.git XML: implemented user-friendly function to deal with default attribute values --- diff --git a/sherlock/xml/parse.c b/sherlock/xml/parse.c index f771b304..2003d091 100644 --- a/sherlock/xml/parse.c +++ b/sherlock/xml/parse.c @@ -654,6 +654,18 @@ xml_attr_find(struct xml_context *ctx, struct xml_node *node, char *name) return xml_attrs_find(ctx->tab_attrs, node, name); } +char * +xml_attr_value(struct xml_context *ctx, struct xml_node *node, char *name) +{ + struct xml_attr *attr = xml_attrs_find(ctx->tab_attrs, node, name); + if (attr) + return attr->val; + if (!node->dtd) + return NULL; + struct xml_dtd_attr *dtd = xml_dtd_find_attr(ctx, node->dtd, name); + return dtd ? dtd->default_value : NULL; +} + void xml_attrs_table_init(struct xml_context *ctx) { diff --git a/sherlock/xml/xml.h b/sherlock/xml/xml.h index 08a4d6f6..99651389 100644 --- a/sherlock/xml/xml.h +++ b/sherlock/xml/xml.h @@ -244,6 +244,9 @@ uns xml_row(struct xml_context *ctx); /* Finds a given attribute value in a XML_NODE_ELEM node */ struct xml_attr *xml_attr_find(struct xml_context *ctx, struct xml_node *node, char *name); +/* Similar to xml_attr_find, but it deals also the default values */ +char *xml_attr_value(struct xml_context *ctx, struct xml_node *node, char *name); + /* The default value of h_find_entity(), knows <, >, &, ' and " */ struct xml_dtd_entity *xml_def_find_entity(struct xml_context *ctx, char *name);