From 49b252868d153df6b259ab5198213a11a1eb1c39 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 13 Sep 2015 16:04:20 +0100 Subject: Use cobble to generate XML data types --- mammoth/docx/xmlparser.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/mammoth/docx/xmlparser.py b/mammoth/docx/xmlparser.py index 43d5eb4..4e963db 100644 --- a/mammoth/docx/xmlparser.py +++ b/mammoth/docx/xmlparser.py @@ -1,9 +1,14 @@ -import collections import xml.sax +import cobble -XmlElementBase = collections.namedtuple("XmlElement", ["name", "attributes", "children"]) -class XmlElement(XmlElementBase): + +@cobble.data +class XmlElement(object): + name = cobble.field() + attributes = cobble.field() + children = cobble.field() + def find_child_or_null(self, name): return self.find_child(name) or _null_xml_element @@ -48,7 +53,9 @@ class NullXmlElement(object): _null_xml_element = NullXmlElement() -XmlText = collections.namedtuple("XmlText", ["value"]) +@cobble.data +class XmlText(object): + value = cobble.field() def element(name, attributes=None, children=None): -- cgit v1.2.3