static css_error node_name(void *pw, void *node, css_qname *qname);
static css_error node_classes(void *pw, void *node,
lwc_string ***classes, uint32_t *n_classes);
+static css_error node_id(void *pw, void *node, lwc_string **id);
/**
return CSS_OK;
}
+
+
+/**
+ * Retrieve the given node's id
+ *
+ * \param pw Pointer to the current SVG parser state
+ * \param node Libdom SVG node
+ * \param id Address at which to store the id
+ *
+ * \return CSS_OK on success, or CSS_NOMEM if anything goes wrong
+ */
+css_error node_id(void *pw, void *node, lwc_string **id)
+{
+ dom_string *attr;
+ dom_exception err;
+ struct svgtiny_parse_state *state;
+
+ /* Begin with the assumption that this node has no id */
+ *id = NULL;
+
+ state = (struct svgtiny_parse_state *)pw;
+ err = dom_element_get_attribute((dom_node *)node,
+ state->interned_id, &attr);
+ if (err != DOM_NO_ERR) {
+ return CSS_NOMEM;
+ }
+ else if (attr == NULL) {
+ /* The node has no id attribute and our return value
+ is already set to NULL so we're done */
+ return CSS_OK;
+ }
+
+ /* If we found an id attribute (a dom_string), intern it into
+ an lwc_string that we can return, and then cleanup the
+ dom_string. */
+ err = dom_string_intern(attr, id);
+ if (err != DOM_NO_ERR) {
+ dom_string_unref(attr);
+ return CSS_NOMEM;
+ }
+ dom_string_unref(attr);
+ return CSS_OK;
+}