missing attributes with default values.
/* Elements */
+struct xml_dtd_elems_table;
+
+static void
+xml_dtd_elems_init_data(struct xml_dtd_elems_table *tab UNUSED, struct xml_dtd_elem *e)
+{
+ slist_init(&e->attrs);
+}
+
#define HASH_PREFIX(x) xml_dtd_elems_##x
#define HASH_NODE struct xml_dtd_elem
#define HASH_KEY_STRING name
#define HASH_WANT_FIND
#define HASH_WANT_LOOKUP
#define HASH_GIVE_ALLOC
+#define HASH_GIVE_INIT_DATA
#define HASH_TABLE_ALLOC
XML_HASH_GIVE_ALLOC
#include "lib/hashtable.h"
{
attr->elem = elem;
attr->name = name;
+ slist_add_tail(&elem->attrs, &attr->n);
}
#define HASH_PREFIX(x) xml_dtd_attrs_##x
uns type;
char *name;
struct xml_dtd_elem_node *node;
+ slist attrs;
void *user; /* User-defined */
};
};
struct xml_dtd_attr {
+ snode n;
char *name; /* Attribute name */
struct xml_dtd_elem *elem; /* Owner element */
uns type; /* See enum xml_dtd_attr_type */
xml_unget_char(ctx);
xml_parse_attr(ctx);
}
+ if (e->dtd)
+ SLIST_FOR_EACH(struct xml_dtd_attr *, a, e->dtd->attrs)
+ if (a->default_mode == XML_ATTR_REQUIRED)
+ {
+ if (!xml_attrs_find(ctx->tab_attrs, e, a->name))
+ xml_error(ctx, "Missing required attribute %s in element <%s>", a->name, e->name);
+ }
+ else if (a->default_mode != XML_ATTR_IMPLIED && ctx->flags & XML_ALLOC_DEFAULT_ATTRS)
+ {
+ struct xml_attr *attr = xml_attrs_lookup(ctx->tab_attrs, e, a->name);
+ if (!attr->val)
+ attr->val = a->default_value;
+ }
if ((ctx->flags & XML_REPORT_TAGS) && ctx->h_stag)
ctx->h_stag(ctx);
}
XML_VALIDATING = 0x00000100, /* Validate everything (not fully implemented!) */
XML_PARSE_DTD = 0x00000200, /* Enable parsing of DTD */
XML_NO_CHARS = 0x00000400, /* The current element must not contain character data (filled automaticaly if using DTD) */
+ XML_ALLOC_DEFAULT_ATTRS = 0x00000800, /* Allocate default attribute values so they can be found by XML_ATTR_FOR_EACH */
/* Internals, do not change! */
XML_EMPTY_ELEM_TAG = 0x00010000, /* The current element match EmptyElemTag */