Using custom parseOptions

This commit is contained in:
Dolan
2018-09-17 23:54:19 +01:00
parent 2e00634bc4
commit 26ee12759c

View File

@ -7,6 +7,12 @@ import { FooterWrapper, IDocumentFooter } from "file/footer-wrapper";
import { HeaderWrapper, IDocumentHeader } from "file/header-wrapper"; import { HeaderWrapper, IDocumentHeader } from "file/header-wrapper";
import { convertToXmlComponent, ImportedXmlComponent, parseOptions } from "file/xml-components"; import { convertToXmlComponent, ImportedXmlComponent, parseOptions } from "file/xml-components";
const importParseOptions = {
...parseOptions,
textNodeName: "",
trimValues: false,
};
const schemeToType = { const schemeToType = {
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/header": "header", "http://schemas.openxmlformats.org/officeDocument/2006/relationships/header": "header",
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer": "footer", "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer": "footer",
@ -55,7 +61,7 @@ export class ImportDocx {
} }
const xmlData = await zipContent.files[`word/${relationFileInfo.targetFile}`].async("text"); const xmlData = await zipContent.files[`word/${relationFileInfo.targetFile}`].async("text");
const xmlObj = fastXmlParser.parse(xmlData, parseOptions); const xmlObj = fastXmlParser.parse(xmlData, importParseOptions);
const importedComp = convertToXmlComponent(headerKey, xmlObj[headerKey]) as ImportedXmlComponent; const importedComp = convertToXmlComponent(headerKey, xmlObj[headerKey]) as ImportedXmlComponent;
@ -72,7 +78,7 @@ export class ImportDocx {
throw new Error(`Can not find target file for id ${footerRef.id}`); throw new Error(`Can not find target file for id ${footerRef.id}`);
} }
const xmlData = await zipContent.files[`word/${relationFileInfo.targetFile}`].async("text"); const xmlData = await zipContent.files[`word/${relationFileInfo.targetFile}`].async("text");
const xmlObj = fastXmlParser.parse(xmlData, parseOptions); const xmlObj = fastXmlParser.parse(xmlData, importParseOptions);
const importedComp = convertToXmlComponent(footerKey, xmlObj[footerKey]) as ImportedXmlComponent; const importedComp = convertToXmlComponent(footerKey, xmlObj[footerKey]) as ImportedXmlComponent;
const footer = new FooterWrapper(this.currentRelationshipId++, importedComp); const footer = new FooterWrapper(this.currentRelationshipId++, importedComp);
@ -102,7 +108,7 @@ export class ImportDocx {
} }
public findReferenceFiles(xmlData: string): IRelationshipFileInfo[] { public findReferenceFiles(xmlData: string): IRelationshipFileInfo[] {
const xmlObj = fastXmlParser.parse(xmlData, parseOptions); const xmlObj = fastXmlParser.parse(xmlData, importParseOptions);
const relationXmlArray = Array.isArray(xmlObj.Relationships.Relationship) const relationXmlArray = Array.isArray(xmlObj.Relationships.Relationship)
? xmlObj.Relationships.Relationship ? xmlObj.Relationships.Relationship
: [xmlObj.Relationships.Relationship]; : [xmlObj.Relationships.Relationship];
@ -119,7 +125,7 @@ export class ImportDocx {
} }
public extractDocumentRefs(xmlData: string): IDocumentRefs { public extractDocumentRefs(xmlData: string): IDocumentRefs {
const xmlObj = fastXmlParser.parse(xmlData, parseOptions); const xmlObj = fastXmlParser.parse(xmlData, importParseOptions);
const sectionProp = xmlObj["w:document"]["w:body"]["w:sectPr"]; const sectionProp = xmlObj["w:document"]["w:body"]["w:sectPr"];
const headersXmlArray = Array.isArray(sectionProp["w:headerReference"]) const headersXmlArray = Array.isArray(sectionProp["w:headerReference"])