Revert "data tree CHANGE anyxml value are now the children directly"
This reverts commit 9f1ef593e8791cf0b55bf48c8924f9f29da5f30c.
Anyxml value again includes the anyxml element itself as
the root. It is necessary if anyxml does not actually
have any children, only text.
Conflicts:
src/parser_xml.c
src/printer_xml.c
diff --git a/src/parser_xml.c b/src/parser_xml.c
index 9fcba55..6a03073 100644
--- a/src/parser_xml.c
+++ b/src/parser_xml.c
@@ -168,7 +168,7 @@
struct lys_node *schema = NULL;
struct lyd_attr *dattr, *dattr_iter;
struct lyxml_attr *attr;
- struct lyxml_elem *first_child, *last_child, *child, *next;
+ struct lyxml_elem *tmp_xml, *child, *next;
int i, havechildren, r;
int ret = 0;
@@ -314,24 +314,27 @@
goto error;
}
} else if (schema->nodetype == LYS_ANYXML && !(options & LYD_OPT_FILTER)) {
- /* unlink xml children, they will be the anyxml value */
- first_child = last_child = NULL;
- LY_TREE_FOR(xml->child, child) {
- lyxml_unlink_elem(ctx, child, 1);
- if (!first_child) {
- first_child = child;
- last_child = child;
- } else {
- last_child->next = child;
- child->prev = last_child;
- last_child = child;
- }
- }
- if (first_child) {
- first_child->prev = last_child;
- }
+ /* HACK unlink xml children and link them to a separate copy of xml */
+ tmp_xml = calloc(1, sizeof *tmp_xml);
+ memcpy(tmp_xml, xml, sizeof *tmp_xml);
+ /* keep attributes in the original */
+ tmp_xml->attr = NULL;
+ /* increase reference counters on strings */
+ tmp_xml->name = lydict_insert(ctx, tmp_xml->name, 0);
+ tmp_xml->content = lydict_insert(ctx, tmp_xml->content, 0);
+ xml->child = NULL;
+ /* xml is correct now */
- ((struct lyd_node_anyxml *)(*result))->value = first_child;
+ LY_TREE_FOR(tmp_xml->child, child) {
+ child->parent = tmp_xml;
+ }
+ /* children are correct now */
+
+ tmp_xml->parent = NULL;
+ lyxml_unlink_elem(ctx, tmp_xml, 1);
+ /* tmp_xml is correct now */
+
+ ((struct lyd_node_anyxml *)*result)->value = tmp_xml;
/* we can safely continue with xml, it's like it was, only without children */
}