Skip to content

Commit

Permalink
When merging xml nodes also merge their attributes.
Browse files Browse the repository at this point in the history
When a model is loaded and an xml node needs to be merged with an existing
xml node, then also add any attributes on the new node not found on the
existing node, to the existing node.
  • Loading branch information
gcampbell512 committed Sep 14, 2023
1 parent 1c9f10b commit 6b0a184
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions schema.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,42 +198,42 @@ merge_nodes (xmlNs * ns, xmlNode * parent, xmlNode * orig, xmlNode * new, int de

for (n = new; n; n = n->next)
{
xmlAttr* attribute = n->properties;

/* Check if this node is already in the existing tree */
for (o = orig; o; o = o->next)
{
if (sch_ns_node_equal (n, o))
{
/* May need to set the model info even if this is a match */
/* Check to see if the model names match */
xmlChar *mod_n = xmlGetProp (n, (xmlChar *)"model");
if (mod_n)
{
xmlChar *mod_o = xmlGetProp (o, (xmlChar *)"model");
if (!mod_o)
if (mod_o)
{
xmlChar *org = xmlGetProp (n, (xmlChar *)"organization");
xmlChar *ver = xmlGetProp (n, (xmlChar *)"version");
xmlChar *feat = xmlGetProp (n, (xmlChar *)"features");
xmlChar *devi = xmlGetProp (n, (xmlChar *)"deviations");
xmlNewProp (o, (const xmlChar *)"model", mod_n);
xmlNewProp (o, (const xmlChar *)"organization", org);
xmlNewProp (o, (const xmlChar *)"version", ver);
xmlNewProp (o, (const xmlChar *)"features", feat);
xmlNewProp (o, (const xmlChar *)"deviations", devi);
xmlFree (org);
xmlFree (ver);
xmlFree (feat);
xmlFree (devi);
if (g_strcmp0 ((char *) mod_o, (char *) mod_n) != 0)
{
xmlChar *name = xmlGetProp (n, (xmlChar *)"name");
syslog (LOG_ERR, "XML: Conflicting model names in same namespace \"%s:%s\" \"%s:%s\"",
(char *) mod_o, (char *) name, (char *) mod_n, (char *) name);
xmlFree (name);
}
xmlFree (mod_o);
}
else if (g_strcmp0 ((char *) mod_o, (char *) mod_n) != 0)
xmlFree (mod_n);
}

/* Merge into the original node any new attributes from the new node */
while (attribute && attribute->name && attribute->children)
{
if (!xmlHasProp (o, attribute->name))
{
xmlChar *name = xmlGetProp (n, (xmlChar *)"name");
syslog (LOG_ERR, "XML: Conflicting model names in same namespace \"%s:%s\" \"%s:%s\"",
(char *) mod_o, (char *) name, (char *) mod_n, (char *) name);
xmlFree (name);
xmlChar* value = xmlNodeListGetString (n->doc, attribute->children, 1);
xmlSetProp (o, attribute->name, value);
xmlFree (value);
}
xmlFree (mod_n);
if (mod_o)
xmlFree (mod_o);
attribute = attribute->next;
}
break;
}
Expand Down

0 comments on commit 6b0a184

Please sign in to comment.