From 61bc4fdd82a04da73aa61a5416ac2fa65fb9e237 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Tue, 3 Dec 2013 00:02:50 +0000 Subject: Add parsing of relationships XML --- mammoth/docx/relationships_xml.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'mammoth') diff --git a/mammoth/docx/relationships_xml.py b/mammoth/docx/relationships_xml.py index 75069fc..bb9c3ed 100644 --- a/mammoth/docx/relationships_xml.py +++ b/mammoth/docx/relationships_xml.py @@ -1,3 +1,6 @@ +import collections + + class Relationships(object): def __init__(self, relationships): self._relationships = relationships @@ -5,6 +8,16 @@ class Relationships(object): def __getitem__(self, key): return self._relationships[key] -class Relationship(object): - def __init__(self, target): - self.target = target + +Relationship = collections.namedtuple("Relationship", ["target"]) + + +def read_relationships_xml_element(element): + children = element.find_children("relationships:Relationship") + return Relationships(dict(map(_read_relationship, children))) + + +def _read_relationship(element): + relationship_id = element.attributes["Id"] + relationship = Relationship(target=element.attributes["Target"]) + return relationship_id, relationship -- cgit v1.2.3