Fixed for XPath

This commit is contained in:
2023-03-03 09:00:37 +01:00
parent fd95d7e845
commit b203bcc0b1

View File

@@ -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 = ""