[elbe-devel] [PATCH 2/7] elbepack: treeutils: allow creation of etree from a string
Thomas Weißschuh
thomas.weissschuh at linutronix.de
Mon Aug 19 16:50:14 CEST 2024
Sometime the XML is already read in memory.
Signed-off-by: Thomas Weißschuh <thomas.weissschuh at linutronix.de>
---
elbepack/treeutils.py | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/elbepack/treeutils.py b/elbepack/treeutils.py
index 5b3d2ed8ee69..6725960d473e 100644
--- a/elbepack/treeutils.py
+++ b/elbepack/treeutils.py
@@ -5,7 +5,7 @@
import copy
from lxml.etree import Element, ElementTree, SubElement
-from lxml.etree import Resolver, XMLParser, XMLSchema, parse, tostring
+from lxml.etree import Resolver, XMLParser, XMLSchema, fromstring, parse, tostring
from elbepack.schema import xml_schema_file
@@ -132,10 +132,12 @@ class elem(ebase):
class etree(ebase):
- def __init__(self, fname):
+ def __init__(self, fname, string=None):
+ parser = XMLParser(huge_tree=True, remove_comments=False)
if fname is not None:
- parser = XMLParser(huge_tree=True, remove_comments=False)
et = parse(fname, parser=parser)
+ elif string is not None:
+ et = fromstring(string, parser=parser).getroottree()
else:
et = ElementTree(file=None)
--
2.46.0
More information about the elbe-devel
mailing list