From 14e630cb35818ad8ce5547ac95b83ed28d6522a9 Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Fri, 29 Mar 2024 22:00:00 +0200 Subject: [PATCH] src/model.c: manage attributes --- src/model.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/model.c b/src/model.c index 4b4b29e..c272f69 100644 --- a/src/model.c +++ b/src/model.c @@ -112,6 +112,48 @@ int model_modify_node(xmlHashTablePtr hashTable, return 0; // Node not found or unable to modify } +/** + * Retrieves the value of an attribute for a node identified by its path. + * + * @param hashTable The hash table containing nodes indexed by their paths. + * @param nodePath The path to the node. + * @param attributeName The name of the attribute. + * @return The value of the attribute, or NULL if not found. + */ +char* model_get_attribute (xmlHashTablePtr hashTable, + const char* nodePath, + const char* attributeName) +{ + xmlNodePtr node = (xmlNodePtr)xmlHashLookup(hashTable, (const xmlChar*)nodePath); + if (node) { + return getAttributeValue(node, attributeName); + } else { + return NULL; + } +} + +/** + * Sets or updates the value of an attribute for a node identified by its path. + * + * @param hashTable The hash table containing nodes indexed by their paths. + * @param nodePath The path to the node. + * @param attributeName The name of the attribute to set. + * @param attributeValue The value to set for the attribute. + * @return 1 on success, 0 on failure. + */ +int model_set_attribute (xmlHashTablePtr hashTable, + const char* nodePath, + const char* attributeName, + const char* attributeValue) +{ + xmlNodePtr node = (xmlNodePtr)xmlHashLookup(hashTable, (const xmlChar*)nodePath); + if (node) { + return setAttributeValue(node, attributeName, attributeValue); + } else { + return 0; + } +} + /* -------------------------------------------------------------------------- */ char model_get_dim (struct model_t *self)