util/datamapper.lua
changeset 11466 d1982b7eb00d
parent 11465 766b0eddd12c
child 11468 6e25409fecbd
--- a/util/datamapper.lua	Fri Mar 19 00:26:04 2021 +0100
+++ b/util/datamapper.lua	Fri Mar 19 01:17:59 2021 +0100
@@ -1,5 +1,7 @@
 local st = require("util.stanza");
 
+local schema_t = {}
+
 local function toboolean(s)
 	if s == "true" or s == "1" then
 		return true
@@ -181,7 +183,7 @@
 	end
 end
 
-local function unparse(schema, t, current_name, current_ns)
+local function unparse(schema, t, current_name, current_ns, ctx)
 
 	if schema.xml then
 		if schema.xml.name then
@@ -193,7 +195,7 @@
 
 	end
 
-	local out = st.stanza(current_name, {xmlns = current_ns})
+	local out = ctx or st.stanza(current_name, {xmlns = current_ns})
 
 	if schema.type == "object" then
 
@@ -268,15 +270,13 @@
 							out:add_direct_child(c);
 						end
 					elseif proptype == "array" and type(propschema) == "table" and type(v) == "table" then
-						local c = unparse(propschema, v, name, namespace);
-						if c then
-							if value_where == "in_wrapper" then
-								local w = st.stanza(propschema.xml.name or name, {xmlns = propschema.xml.namespace or namespace})
-								w:add_direct_child(c);
-								out:add_direct_child(w);
-							else
+						if value_where == "in_wrapper" then
+							local c = unparse(propschema, v, name, namespace);
+							if c then
 								out:add_direct_child(c);
 							end
+						else
+							unparse(propschema, v, name, namespace, out);
 						end
 					else
 						error("NYI")