Fixed #94 and done some refactoring #99

Merged
bema merged 10 commits from bema/fix/libxml_headers into master 2023-03-03 10:43:34 +01:00
Showing only changes of commit b203bcc0b1 - Show all commits

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