From 5bbf77cef9ca98890bf271388e4f06b59bf301e5 Mon Sep 17 00:00:00 2001 From: Adrian of Doom <52701496+futzu@users.noreply.github.com> Date: Tue, 26 Nov 2024 19:51:06 -0500 Subject: [PATCH] strip unknown xml elements when parsing. --- threefive/xml.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/threefive/xml.py b/threefive/xml.py index 420b568f..2f553280 100644 --- a/threefive/xml.py +++ b/threefive/xml.py @@ -378,6 +378,8 @@ class XmlParser: def __init__(self): self.active = None self.node_list = [] + self.open_nodes=[] + self.parent=None def chk_node_list(self, node): """ @@ -403,10 +405,12 @@ def mk_active(self, node): """ mk_active sets self.active to the current node name. """ + self.active=None name = node[1:].split(" ", 1)[0].split(">", 1)[0] name = strip_ns(name) self.active = name.replace("/", "").replace(">", "") + def _split_attrs(self, node): node = node.replace("='", '="').replace("' ", '" ') attrs = [x for x in node.split(" ") if "=" in x] @@ -430,7 +434,9 @@ def parse(self, exemel, descriptor_parse=False): """ parse parses an xml string for a SCTE-35 Cue. """ - stuff = {"descriptors": []} + stuff={} + if not descriptor_parse: + stuff = {"descriptors": []} data = exemel.replace("\n", "").strip() while ">" in data: self.mk_active(data) @@ -453,7 +459,8 @@ def _parse_most(self, data, stuff): self.chk_node_list(this_node) attrs = self.mk_attrs(this_node) if self.active not in stuff: - stuff[self.active] = attrs + if self.active not in ['!--','']: + stuff[self.active] = attrs data = data[ridx + 1 :] if "<" in data: lidx = data.index("<")