diff options
| author | Michael Williamson <mike@zwobble.org> | 2013-12-03 00:02:50 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2013-12-03 00:02:50 +0000 |
| commit | 61bc4fdd82a04da73aa61a5416ac2fa65fb9e237 (patch) | |
| tree | 7110808fb27f65f1ad5611ab372620b0067eb61a /mammoth/docx/relationships_xml.py | |
| parent | 8717dd906667c5bf7a6c11f202ab475b14456990 (diff) | |
Add parsing of relationships XML
Diffstat (limited to 'mammoth/docx/relationships_xml.py')
| -rw-r--r-- | mammoth/docx/relationships_xml.py | 19 |
1 files changed, 16 insertions, 3 deletions
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 |
