Skip to content

Commit

Permalink
More support for NETCONF XPATH 1.0
Browse files Browse the repository at this point in the history
Added a more support functions to manipulate schema nodes and
look ups.
  • Loading branch information
gcampbell512 committed Nov 28, 2023
1 parent 113bbd6 commit f9fb3ef
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
4 changes: 4 additions & 0 deletions apteryx-xml.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ GList *sch_get_loaded_models (sch_instance * instance);
sch_node *sch_child_first (sch_instance *instance);
sch_node *sch_node_parent (sch_node *node);
sch_node *sch_node_child (sch_node *parent, const char *name);
sch_node *sch_node_namespace_child (sch_node * parent, const char *namespace, const char *child);
sch_node *sch_node_by_namespace (sch_instance * instance, const char *namespace,
const char *prefix);
sch_node *sch_node_child_first (sch_node * parent);
sch_node *sch_node_next_sibling (sch_node * node);
sch_node *sch_preorder_next (sch_node *current, sch_node *root);
Expand All @@ -73,6 +76,7 @@ char *sch_model (sch_node * node, bool ignore_ancestors);
char *sch_organization (sch_node * node);
char *sch_version (sch_node * node);
char *sch_namespace (sch_node * node);
char *sch_prefix (sch_node * node);
char *sch_default_value (sch_node * node);
char *sch_path (sch_node * node);
bool sch_is_leaf (sch_node * node);
Expand Down
45 changes: 45 additions & 0 deletions schema.c
Original file line number Diff line number Diff line change
Expand Up @@ -1257,6 +1257,40 @@ sch_node_child (sch_node * parent, const char *child)
return _sch_node_child (ns, parent, child);
}

sch_node *
sch_node_namespace_child (sch_node * parent, const char *namespace, const char *child)
{

xmlNs *ns;
xmlNode *module;
sch_node *node;
module = xmlNewNode (NULL, (xmlChar *) "MODULE");
ns = xmlNewNs (module, (const xmlChar *) namespace, NULL);
node = _sch_node_child (ns, parent, child);

/* Note the ns is freed as part of the xmlFreeNode */
xmlFreeNode (module);
return node;
}

sch_node *
sch_node_by_namespace (sch_instance * instance, const char *namespace, const char *prefix)
{
xmlNode *xml = sch_child_first (instance);

while (xml && xml->type == XML_ELEMENT_NODE)
{
if (xml->ns &&
((namespace && xml->ns->href && g_strcmp0 ((char *) xml->ns->href, namespace) == 0) ||
(!namespace && prefix &&
xml->ns->prefix && g_strcmp0 ((char *) xml->ns->prefix, prefix) == 0)))
return xml;

xml = xml->next;
}
return NULL;
}

sch_node *
sch_node_child_first (sch_node *parent)
{
Expand Down Expand Up @@ -1401,6 +1435,17 @@ sch_namespace (sch_node * node)
return NULL;
}

char *
sch_prefix (sch_node * node)
{
xmlNode *xml = ((xmlNode *) node);
if (xml->ns && xml->ns->prefix)
{
return g_strdup ((char *) xml->ns->prefix);
}
return NULL;
}

char *
sch_default_value (sch_node * node)
{
Expand Down

0 comments on commit f9fb3ef

Please sign in to comment.