summaryrefslogtreecommitdiffstats
path: root/src/printer_xml.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/printer_xml.c')
-rw-r--r--src/printer_xml.c47
1 files changed, 33 insertions, 14 deletions
diff --git a/src/printer_xml.c b/src/printer_xml.c
index a7f4c73..9cd6774 100644
--- a/src/printer_xml.c
+++ b/src/printer_xml.c
@@ -110,7 +110,9 @@ xml_print_ns_opaq(struct xmlpr_ctx *pctx, LY_VALUE_FORMAT format, const struct l
{
switch (format) {
case LY_VALUE_XML:
- return xml_print_ns(pctx, name->module_ns, (prefix_opts & LYXML_PREFIX_DEFAULT) ? NULL : name->prefix, prefix_opts);
+ if (name->module_ns) {
+ return xml_print_ns(pctx, name->module_ns, (prefix_opts & LYXML_PREFIX_DEFAULT) ? NULL : name->prefix, prefix_opts);
+ }
break;
case LY_VALUE_JSON:
if (name->module_name) {
@@ -178,6 +180,8 @@ xml_print_meta(struct xmlpr_ctx *pctx, const struct lyd_node *node)
struct ly_set ns_list = {0};
LY_ARRAY_COUNT_TYPE u;
ly_bool dynamic, filter_attrs = 0;
+ const char *value;
+ uint32_t i;
/* with-defaults */
if (node->schema->nodetype & LYD_NODE_TERM) {
@@ -205,11 +209,14 @@ xml_print_meta(struct xmlpr_ctx *pctx, const struct lyd_node *node)
}
for (meta = node->meta; meta; meta = meta->next) {
- const char *value = meta->value.realtype->plugin->print(LYD_CTX(node), &meta->value, LY_VALUE_XML, &ns_list,
- &dynamic, NULL);
+ /* store the module of the default namespace, NULL because there is none */
+ ly_set_add(&ns_list, NULL, 0, NULL);
+
+ /* print the value */
+ value = meta->value.realtype->plugin->print(LYD_CTX(node), &meta->value, LY_VALUE_XML, &ns_list, &dynamic, NULL);
/* print namespaces connected with the value's prefixes */
- for (uint32_t i = 0; i < ns_list.count; ++i) {
+ for (i = 1; i < ns_list.count; ++i) {
mod = ns_list.objs[i];
xml_print_ns(pctx, mod->ns, mod->prefix, 1);
}
@@ -314,22 +321,32 @@ static LY_ERR xml_print_node(struct xmlpr_ctx *pctx, const struct lyd_node *node
static LY_ERR
xml_print_term(struct xmlpr_ctx *pctx, const struct lyd_node_term *node)
{
+ LY_ERR rc = LY_SUCCESS;
struct ly_set ns_list = {0};
- ly_bool dynamic;
- const char *value;
+ ly_bool dynamic = 0;
+ const char *value = NULL;
+ const struct lys_module *mod;
+ uint32_t i;
- xml_print_node_open(pctx, &node->node);
+ /* store the module of the default namespace */
+ if ((rc = ly_set_add(&ns_list, node->schema->module, 0, NULL))) {
+ LOGMEM(pctx->ctx);
+ goto cleanup;
+ }
+
+ /* print the value */
value = ((struct lysc_node_leaf *)node->schema)->type->plugin->print(LYD_CTX(node), &node->value, LY_VALUE_XML,
&ns_list, &dynamic, NULL);
- LY_CHECK_RET(!value, LY_EINVAL);
+ LY_CHECK_ERR_GOTO(!value, rc = LY_EINVAL, cleanup);
- /* print namespaces connected with the values's prefixes */
- for (uint32_t u = 0; u < ns_list.count; ++u) {
- const struct lys_module *mod = (const struct lys_module *)ns_list.objs[u];
+ /* print node opening */
+ xml_print_node_open(pctx, &node->node);
+ /* print namespaces connected with the values's prefixes */
+ for (i = 1; i < ns_list.count; ++i) {
+ mod = ns_list.objs[i];
ly_print_(pctx->out, " xmlns:%s=\"%s\"", mod->prefix, mod->ns);
}
- ly_set_erase(&ns_list, NULL);
if (!value[0]) {
ly_print_(pctx->out, "/>%s", DO_FORMAT ? "\n" : "");
@@ -338,11 +355,13 @@ xml_print_term(struct xmlpr_ctx *pctx, const struct lyd_node_term *node)
lyxml_dump_text(pctx->out, value, 0);
ly_print_(pctx->out, "</%s>%s", node->schema->name, DO_FORMAT ? "\n" : "");
}
+
+cleanup:
+ ly_set_erase(&ns_list, NULL);
if (dynamic) {
free((void *)value);
}
-
- return LY_SUCCESS;
+ return rc;
}
/**