document-xml-reader.js 864 B

123456789101112131415161718192021222324252627282930
  1. exports.DocumentXmlReader = DocumentXmlReader;
  2. var documents = require("../documents");
  3. var Result = require("../results").Result;
  4. function DocumentXmlReader(options) {
  5. var bodyReader = options.bodyReader;
  6. function convertXmlToDocument(element) {
  7. var body = element.first("w:body");
  8. if (body == null) {
  9. throw new Error("Could not find the body element: are you sure this is a docx file?");
  10. }
  11. var result = bodyReader.readXmlElements(body.children)
  12. .map(function(children) {
  13. return new documents.Document(children, {
  14. notes: options.notes,
  15. comments: options.comments
  16. });
  17. });
  18. return new Result(result.value, result.messages);
  19. }
  20. return {
  21. convertXmlToDocument: convertXmlToDocument
  22. };
  23. }