WIP: devel : travail du mois de mars/avril #28
32
src/model.c
32
src/model.c
|
@ -58,26 +58,26 @@ void model_populate_hashtable (xmlNode *node,
|
|||
|
||||
// Skip text nodes and others that are not element nodes
|
||||
if (node->type != XML_ELEMENT_NODE) {
|
||||
model_populate_hashtable(node->next, hashTable, currentPath);
|
||||
model_populate_hashtable (node->next, hashTable, currentPath);
|
||||
return;
|
||||
}
|
||||
|
||||
// Calculate new path
|
||||
char newPath[1024]; // large enough
|
||||
if (currentPath && strlen(currentPath) > 0) {
|
||||
snprintf(newPath, sizeof(newPath), "%s/%s", currentPath, node->name);
|
||||
snprintf (newPath, sizeof(newPath), "%s/%s", currentPath, node->name);
|
||||
} else {
|
||||
snprintf(newPath, sizeof(newPath), "%s", node->name); // Root element
|
||||
snprintf (newPath, sizeof(newPath), "%s", node->name); // Root element
|
||||
}
|
||||
|
||||
// Add current node to hash table with its path as the key
|
||||
xmlHashAddEntry(hashTable, (const xmlChar *)newPath, node);
|
||||
xmlHashAddEntry (hashTable, (const xmlChar *)newPath, node);
|
||||
|
||||
// Recurse into child nodes with the updated path
|
||||
model_populate_hashtable(node->children, hashTable, newPath);
|
||||
model_populate_hashtable (node->children, hashTable, newPath);
|
||||
|
||||
// Continue with the next sibling
|
||||
model_populate_hashtable(node->next, hashTable, currentPath);
|
||||
model_populate_hashtable (node->next, hashTable, currentPath);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -110,9 +110,9 @@ int model_modify_node (const char *path,
|
|||
xmlNodePtr node = model_find_node_by_path(hashTable, path);
|
||||
if (node) {
|
||||
// Free the current content of the node, if any
|
||||
xmlNodeSetContent(node, (const xmlChar *)""); // Clear existing content
|
||||
xmlNodeSetContent (node, (const xmlChar *)""); // Clear existing content
|
||||
// Set new content
|
||||
xmlNodeSetContent(node, (const xmlChar *)newContent);
|
||||
xmlNodeSetContent (node, (const xmlChar *)newContent);
|
||||
return 1; // Success
|
||||
}
|
||||
return 0; // Node not found or unable to modify
|
||||
|
@ -131,9 +131,9 @@ char* model_get_attribute (const char* nodePath,
|
|||
{
|
||||
assert(hashTable != NULL);
|
||||
|
||||
xmlNodePtr node = (xmlNodePtr)xmlHashLookup(hashTable, (const xmlChar*)nodePath);
|
||||
xmlNodePtr node = (xmlNodePtr)xmlHashLookup (hashTable, (const xmlChar*)nodePath);
|
||||
if (node) {
|
||||
return getAttributeValue(node, attributeName);
|
||||
return getAttributeValue (node, attributeName);
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -154,9 +154,9 @@ int model_set_attribute (const char* nodePath,
|
|||
{
|
||||
assert(hashTable != NULL);
|
||||
|
||||
xmlNodePtr node = (xmlNodePtr)xmlHashLookup(hashTable, (const xmlChar*)nodePath);
|
||||
xmlNodePtr node = (xmlNodePtr)xmlHashLookup (hashTable, (const xmlChar*)nodePath);
|
||||
if (node) {
|
||||
return setAttributeValue(node, attributeName, attributeValue);
|
||||
return setAttributeValue (node, attributeName, attributeValue);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
|
@ -188,17 +188,17 @@ xmlNodePtr model_copy_node(struct model_t *self,
|
|||
}
|
||||
|
||||
// Modify the specified attribute in the copied node
|
||||
xmlSetProp(copiedNode, (const xmlChar*)attributeName, (const xmlChar*)newAttributeValue);
|
||||
xmlSetProp (copiedNode, (const xmlChar*)attributeName, (const xmlChar*)newAttributeValue);
|
||||
|
||||
// Insert the copied node as the next sibling of the original node
|
||||
xmlAddNextSibling(node, copiedNode);
|
||||
xmlAddNextSibling (node, copiedNode);
|
||||
|
||||
// Calculate the new node's path.
|
||||
char newPath[1024];
|
||||
snprintf(newPath, sizeof(newPath), "%s_copy", originalNodePath);
|
||||
snprintf (newPath, sizeof(newPath), "%s_copy", originalNodePath);
|
||||
|
||||
// Update the hashtable with the new node's path
|
||||
xmlHashAddEntry(hashTable, (const xmlChar*)newPath, copiedNode);
|
||||
xmlHashAddEntry (hashTable, (const xmlChar*)newPath, copiedNode);
|
||||
|
||||
return copiedNode;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue