From b203bcc0b1bd1aca9337289e7778139653772f33 Mon Sep 17 00:00:00 2001 From: Adam Bem Date: Fri, 3 Mar 2023 09:00:37 +0100 Subject: [PATCH] Fixed for XPath --- Backend-libXML/Parser.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Backend-libXML/Parser.py b/Backend-libXML/Parser.py index 14ce916..e019649 100644 --- a/Backend-libXML/Parser.py +++ b/Backend-libXML/Parser.py @@ -1,5 +1,5 @@ from lxml import etree - +from io import BytesIO def prettify(source: str) -> str: """Method used to pretty format given XML @@ -48,8 +48,8 @@ def xpath(source: str, xpath: str) -> str: :return: Nodes selected using XPath """ - - root = etree.XML(source) + byte_input = BytesIO(source.encode("utf-8")) + root = etree.parse(byte_input).getroot() nsmap = root.nsmap # LXML doesn't accept empty (None) namespace prefix, @@ -61,7 +61,7 @@ def xpath(source: str, xpath: str) -> str: # 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: + if type(result) is not list: return str(result) else: result_string = ""