Skip to content

Commit 67fcb92

Browse files
committed
[OpenDataServices/cove#777] Allow duplicate XML elements with text
(this is needed to have multiple narrative elements)
1 parent fb28676 commit 67fcb92

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

flattentool/input.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -549,8 +549,9 @@ def unflatten_main_with_parser(parser, line, timezone, xml, id_name):
549549
if current_type and current_type != 'array':
550550
raise ValueError("There is an array at '{}' when the schema says there should be a '{}'".format(path_till_now, current_type))
551551
list_index = int(next_path_item)
552+
current_type = 'array'
552553

553-
if isint(next_path_item) or current_type == 'array':
554+
if current_type == 'array':
554555
list_as_dict = current_path.get(path_item)
555556
if list_as_dict is None:
556557
list_as_dict = ListAsDict()
@@ -564,7 +565,10 @@ def unflatten_main_with_parser(parser, line, timezone, xml, id_name):
564565
new_path = OrderedDict()
565566
list_as_dict[list_index] = new_path
566567
current_path = new_path
567-
continue
568+
if not xml or num < len(path_list)-2:
569+
# In xml "arrays" can have text values, if they're the final element
570+
# This corresponds to a tag with text, but also possibly attributes
571+
continue
568572

569573
## Object
570574
if current_type == 'object' or (not current_type and next_path_item):
@@ -578,7 +582,7 @@ def unflatten_main_with_parser(parser, line, timezone, xml, id_name):
578582
break
579583
current_path = new_path
580584
continue
581-
if current_type and current_type != 'object' and next_path_item:
585+
if current_type and current_type not in ['object', 'array'] and next_path_item:
582586
raise ValueError("There is an object or list at '{}' but it should be an {}".format(path_till_now, current_type))
583587

584588
## Other Types
@@ -607,7 +611,9 @@ def unflatten_main_with_parser(parser, line, timezone, xml, id_name):
607611
if path_item.startswith('@'):
608612
current_path[path_item] = cell
609613
else:
610-
if path_item not in current_path:
614+
if current_type == 'array':
615+
current_path['text()'] = cell
616+
elif path_item not in current_path:
611617
current_path[path_item] = {'text()': cell}
612618
else:
613619
current_path[path_item]['text()'] = cell

0 commit comments

Comments
 (0)