From a9dd85b3f6cf45be35b89a705ca9d1f57082ba3e Mon Sep 17 00:00:00 2001 From: Adam Bem Date: Wed, 1 Mar 2023 11:30:31 +0100 Subject: [PATCH 1/2] Fixed libXml --- Backend-libXML/Parser.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Backend-libXML/Parser.py b/Backend-libXML/Parser.py index 827b356..adef230 100644 --- a/Backend-libXML/Parser.py +++ b/Backend-libXML/Parser.py @@ -56,10 +56,13 @@ def xpath(source: str, xpath: str) -> str: nsmap.pop(None) result = root.xpath(xpath, namespaces=nsmap) - result_string = "" - for e in result: - result_string += etree.tostring(e, pretty_print=True).decode() + "\n" - return result_string + if isinstance(result, etree._ElementUnicodeResult): + return str(result) + else: + result_string = "" + for e in result: + result_string += etree.tostring(e, pretty_print=True).decode() + "\n" + return result_string -- 2.51.0 From 7e31b52153e29792a4d035270cf6e333473048a9 Mon Sep 17 00:00:00 2001 From: Adam Bem Date: Wed, 1 Mar 2023 11:43:49 +0100 Subject: [PATCH 2/2] Added comments and returned back to previous solution --- Backend-libXML/Parser.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Backend-libXML/Parser.py b/Backend-libXML/Parser.py index adef230..c7f89ce 100644 --- a/Backend-libXML/Parser.py +++ b/Backend-libXML/Parser.py @@ -56,7 +56,10 @@ def xpath(source: str, xpath: str) -> str: nsmap.pop(None) result = root.xpath(xpath, namespaces=nsmap) - if isinstance(result, etree._ElementUnicodeResult): + + # root.xpath can return 4 types: float, string, bool and list. + # List is the only one that can't be simply converted to str + if result is not list: return str(result) else: result_string = "" -- 2.51.0