processFootEndNotes method

void processFootEndNotes(
  1. ArchiveFile? footNoteFile,
  2. ArchiveFile? endNoteFile,
  3. List<FootEndNote> footNotes,
  4. List<FootEndNote> endNotes,
)

Function for processing footnotes and endnotes

Implementation

void processFootEndNotes(ArchiveFile? footNoteFile, ArchiveFile? endNoteFile, List<FootEndNote> footNotes, List<FootEndNote> endNotes) {
  if (footNoteFile != null) {
    final fileContent = utf8.decode(footNoteFile.content);
    final document = xml.XmlDocument.parse(fileContent);
    var footNts = document.findAllElements("w:footnote");
    if (footNts.isNotEmpty) {
      for (var footNt in footNts) {
        String id = "";
        String pStyle = "";
        String rStyle = "";
        String text = "";
        var tempId = footNt.getAttribute("w:id");
        if (tempId != null) {
          id = tempId;
        }
        var chkPStyle = footNt.findAllElements("w:pStyle");
        if (chkPStyle.isNotEmpty) {
          var tempPStyle = chkPStyle.first.getAttribute("w:val");
          if (tempPStyle != null) {
            pStyle = tempPStyle;
          }
        }
        var chkrStyle = footNt.findAllElements("w:rStyle");
        if (chkrStyle.isNotEmpty) {
          var tempRStyle = chkrStyle.first.getAttribute("w:val");
          if (tempRStyle != null) {
            rStyle = tempRStyle;
          }
        }
        var chkText = footNt.findAllElements("w:t");
        if (chkText.isNotEmpty) {
          var tempText = chkText.first.innerText;
          if (tempText.isNotEmpty) {
            text = tempText;
          }
        }
        footNotes.add(FootEndNote(id, pStyle, rStyle, text));
      }
    }
  }
  if (endNoteFile != null) {
    final fileContent = utf8.decode(endNoteFile.content);
    final document = xml.XmlDocument.parse(fileContent);
    var endNts = document.findAllElements("w:endnote");
    if (endNts.isNotEmpty) {
      for (var endNt in endNts) {
        String id = "";
        String pStyle = "";
        String rStyle = "";
        String text = "";
        var tempId = endNt.getAttribute("w:id");
        if (tempId != null) {
          id = tempId;
        }
        var chkPStyle = endNt.findAllElements("w:pStyle");
        if (chkPStyle.isNotEmpty) {
          var tempPStyle = chkPStyle.first.getAttribute("w:val");
          if (tempPStyle != null) {
            pStyle = tempPStyle;
          }
        }
        var chkrStyle = endNt.findAllElements("w:rStyle");
        if (chkrStyle.isNotEmpty) {
          var tempRStyle = chkrStyle.first.getAttribute("w:val");
          if (tempRStyle != null) {
            rStyle = tempRStyle;
          }
        }
        var chkText = endNt.findAllElements("w:t");
        if (chkText.isNotEmpty) {
          var tempText = chkText.first.innerText;
          if (tempText.isNotEmpty) {
            text = tempText;
          }
        }
        endNotes.add(FootEndNote(id, pStyle, rStyle, text));
      }
    }
  }
}