src/model.c: manage attributes

This commit is contained in:
Adrien Bourmault 2024-03-29 22:00:00 +02:00
parent 38cbe2a443
commit 14e630cb35
Signed by: neox
GPG Key ID: 95F65F55F682A17A
1 changed files with 42 additions and 0 deletions

View File

@ -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)