diff options
| author | Michael Williamson <mike@zwobble.org> | 2024-02-18 13:01:07 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2024-02-18 13:01:07 +0000 |
| commit | 687e940b8c5e286ef2eed604b0f77d4eac9890bd (patch) | |
| tree | 32241b1b095cb8ca22a501ab0306a1318d9cae24 | |
| parent | c2c6dd1714bd02f7e516746daf3d22938e6407ee (diff) | |
Add namespace mapping for relationships
| -rw-r--r-- | lib/docx/office-xml-reader.js | 1 | ||||
| -rw-r--r-- | lib/docx/relationships-reader.js | 6 | ||||
| -rw-r--r-- | test/docx/relationships-reader.tests.js | 4 |
3 files changed, 6 insertions, 5 deletions
diff --git a/lib/docx/office-xml-reader.js b/lib/docx/office-xml-reader.js index dccc365..f076e2c 100644 --- a/lib/docx/office-xml-reader.js +++ b/lib/docx/office-xml-reader.js @@ -24,6 +24,7 @@ var xmlNamespaceMap = { // Common "http://schemas.openxmlformats.org/package/2006/content-types": "content-types", + "http://schemas.openxmlformats.org/package/2006/relationships": "relationships", "http://schemas.openxmlformats.org/markup-compatibility/2006": "mc", "urn:schemas-microsoft-com:vml": "v", "urn:schemas-microsoft-com:office:word": "office-word" diff --git a/lib/docx/relationships-reader.js b/lib/docx/relationships-reader.js index 4db172e..5f54f42 100644 --- a/lib/docx/relationships-reader.js +++ b/lib/docx/relationships-reader.js @@ -6,7 +6,7 @@ exports.Relationships = Relationships; function readRelationships(element) { var relationships = []; element.children.forEach(function(child) { - if (child.name === "{http://schemas.openxmlformats.org/package/2006/relationships}Relationship") { + if (child.name === "relationships:Relationship") { var relationship = { relationshipId: child.attributes.Id, target: child.attributes.Target, @@ -23,7 +23,7 @@ function Relationships(relationships) { relationships.forEach(function(relationship) { targetsByRelationshipId[relationship.relationshipId] = relationship.target; }); - + var targetsByType = {}; relationships.forEach(function(relationship) { if (!targetsByType[relationship.type]) { @@ -31,7 +31,7 @@ function Relationships(relationships) { } targetsByType[relationship.type].push(relationship.target); }); - + return { findTargetByRelationshipId: function(relationshipId) { return targetsByRelationshipId[relationshipId]; diff --git a/test/docx/relationships-reader.tests.js b/test/docx/relationships-reader.tests.js index 1427b1c..c9afee5 100644 --- a/test/docx/relationships-reader.tests.js +++ b/test/docx/relationships-reader.tests.js @@ -57,9 +57,9 @@ test("when there are no relationships of requested type then empty array is retu function relationshipsElement(children) { - return xml.element("{http://schemas.openxmlformats.org/package/2006/relationships}Relationships", {}, children); + return xml.element("relationships:Relationships", {}, children); } function relationshipElement(attributes) { - return xml.element("{http://schemas.openxmlformats.org/package/2006/relationships}Relationship", attributes, []); + return xml.element("relationships:Relationship", attributes, []); } |
