Software /
code /
prosody
Diff
util/datamapper.lua @ 11466:c098d07e6717
util.datamapper: Finally implement support for parsing arrays
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 20 Mar 2021 20:45:06 +0100 |
parent | 11465:19a88b61ab4e |
child | 11467:88792dd2bee9 |
line wrap: on
line diff
--- a/util/datamapper.lua Sat Mar 20 19:02:18 2021 +0100 +++ b/util/datamapper.lua Sat Mar 20 20:45:06 2021 +0100 @@ -27,7 +27,7 @@ local function unpack_propschema(propschema, propname, current_ns) local proptype = "string" - local value_where = "in_text_tag" + local value_where = propname and "in_text_tag" or "in_text" local name = propname local namespace = current_ns local prefix @@ -158,21 +158,17 @@ end function parse_array(schema, s) - local proptype, value_where, child_name, namespace = unpack_propschema(schema.items, nil, s.attr.xmlns) + local proptype, value_where, child_name, namespace, prefix, single_attribute, enums = unpack_propschema(schema.items, nil, s.attr.xmlns) + local attr_name + if value_where == "in_single_attribute" then + value_where = "in_attribute"; + attr_name = single_attribute; + end local out = {} for c in s:childtags(child_name, namespace) do - local value; - if value_where == "in_text_tag" then - value = c:get_text(); - else - error("NYI") - end + local value = extract_value(c, value_where, proptype, attr_name or child_name, namespace, prefix, single_attribute, enums) - value = totype(proptype, value) - - if value ~= nil then - table.insert(out, value); - end + table.insert(out, totype(proptype, value)); end return out end