From 6b040ed3f347e34fc89013ff7dc9268c733cee47 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sat, 27 Apr 2013 22:46:17 +0100 Subject: Move relationship reading into separate module --- lib/relationships-reader.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 lib/relationships-reader.js (limited to 'lib/relationships-reader.js') diff --git a/lib/relationships-reader.js b/lib/relationships-reader.js new file mode 100644 index 0000000..fe6c7f1 --- /dev/null +++ b/lib/relationships-reader.js @@ -0,0 +1,25 @@ +var readXmlFromZipFile = require("./office-xml-reader").readXmlFromZipFile; + + +exports.readRelationshipsFromZipFile = readRelationshipsFromZipFile; + + +function readRelationshipsFromZipFile(file) { + return readXmlFromZipFile(file, "word/_rels/document.xml.rels") + .then(function(relationshipsXml) { + return relationshipsXml ? readRelationships(relationshipsXml) : {}; + }); +} + + +function readRelationships(relationshipsXml) { + var relationships = {}; + relationshipsXml.root.children.forEach(function(child) { + if (child.name === "{http://schemas.openxmlformats.org/package/2006/relationships}:Relationship") { + relationships[child.attributes.Id] = { + target: child.attributes.Target + }; + } + }); + return relationships; +} -- cgit v1.2.3