aboutsummaryrefslogtreecommitdiff
path: root/mammoth/xmlparser.py
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2013-12-01 11:40:55 +0000
committerMichael Williamson <mike@zwobble.org>2013-12-01 11:40:55 +0000
commit833c867189d757efb5b13e1e783869a4039860de (patch)
treea967c7492c3390055c57a10a507d80755da0486a /mammoth/xmlparser.py
parent8d1cc0932083a686e24ff02c9819e507fbb2cb9f (diff)
Create null XML element
Diffstat (limited to 'mammoth/xmlparser.py')
-rw-r--r--mammoth/xmlparser.py20
1 files changed, 19 insertions, 1 deletions
diff --git a/mammoth/xmlparser.py b/mammoth/xmlparser.py
index 8b26777..d58ea75 100644
--- a/mammoth/xmlparser.py
+++ b/mammoth/xmlparser.py
@@ -2,7 +2,25 @@ import collections
import xml.sax
-XmlElement = collections.namedtuple("XmlElement", ["name", "attributes", "children"])
+XmlElementBase = collections.namedtuple("XmlElement", ["name", "attributes", "children"])
+class XmlElement(XmlElementBase):
+ def find_child_or_null(self, name):
+ for child in self.children:
+ if child.name == name:
+ return child
+ return _null_xml_element
+
+
+class NullXmlElement(object):
+ attributes = {}
+
+ def find_child_or_null(self, name):
+ return self
+
+
+_null_xml_element = NullXmlElement()
+
+
XmlText = collections.namedtuple("XmlText", ["value"])