]> mj.ucw.cz Git - libucw.git/commitdiff
XML: implemented user-friendly function to deal with default attribute values
authorPavel Charvat <pavel.charvat@netcentrum.cz>
Thu, 24 Apr 2008 07:32:58 +0000 (09:32 +0200)
committerPavel Charvat <pavel.charvat@netcentrum.cz>
Thu, 24 Apr 2008 07:32:58 +0000 (09:32 +0200)
sherlock/xml/parse.c
sherlock/xml/xml.h

index f771b304162bddc1d272115cd855eee60a675f12..2003d091091b51eef42bbd5207b05405577baca8 100644 (file)
@@ -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)
 {
index 08a4d6f681a00c3337fc73cbfff3abd64c0ca3e3..996513898c1ba896f336360daab28997e8127473 100644 (file)
@@ -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 &lt;, &gt;, &amp;, &apos; and &quot; */
 struct xml_dtd_entity *xml_def_find_entity(struct xml_context *ctx, char *name);