From e75c5196b3dc475ea41ab84cff6d312458d28f68 Mon Sep 17 00:00:00 2001 From: Mazztok45 Date: Wed, 6 Dec 2023 18:24:33 +0100 Subject: [PATCH] improvement of the indentation of the xml output by appending children nodes into their respective parent nodes --- src/zbmath_rest2oai/getWithSwagger.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/zbmath_rest2oai/getWithSwagger.py b/src/zbmath_rest2oai/getWithSwagger.py index 4483438..c58b601 100644 --- a/src/zbmath_rest2oai/getWithSwagger.py +++ b/src/zbmath_rest2oai/getWithSwagger.py @@ -73,7 +73,14 @@ def func_get_doc_to_xml(obj, xml): elif obj[i] is None: xml = append_text_child(xmld, xml, xml.lastChild.nodeName, 'missing') elif type(obj[i]) in [str,int]: - xml = append_text_child(xmld, xml, xml.lastChild.nodeName, obj[i]) + parent_name = xml.lastChild.nodeName + if parent_name.endswith('s'): + parent_name = parent_name[:-1] + + if xml._get_lastChild().nodeName == parent_name: + xml = append_text_child(xmld, xml, parent_name, obj[i]) + else: + xml = append_text_child(xmld, xml._get_lastChild(), parent_name, obj[i]) elif type(obj[i]) in all_iter_list: func_get_doc_to_xml(obj[i], xml) else: @@ -94,10 +101,8 @@ def func_get_doc_to_xml(obj, xml): func_get_doc_to_xml(obj[key], xml) return xml -print(func_get_doc_to_xml(res.result, ron).toprettyxml()) - - - +final_xml = func_get_doc_to_xml(res.result, ron) +print(final_xml.toprettyxml())