Skip to content

Commit

Permalink
Add namespace mapping for relationships
Browse files Browse the repository at this point in the history
  • Loading branch information
mwilliamson committed Feb 18, 2024
1 parent c2c6dd1 commit 687e940
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions lib/docx/office-xml-reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions lib/docx/relationships-reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -23,15 +23,15 @@ function Relationships(relationships) {
relationships.forEach(function(relationship) {
targetsByRelationshipId[relationship.relationshipId] = relationship.target;
});

var targetsByType = {};
relationships.forEach(function(relationship) {
if (!targetsByType[relationship.type]) {
targetsByType[relationship.type] = [];
}
targetsByType[relationship.type].push(relationship.target);
});

return {
findTargetByRelationshipId: function(relationshipId) {
return targetsByRelationshipId[relationshipId];
Expand Down
4 changes: 2 additions & 2 deletions test/docx/relationships-reader.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, []);
}

0 comments on commit 687e940

Please sign in to comment.