Collections.sort(xpaths,this);
for(String xpath : xpaths) {
XSSFSingleXmlCell simpleXmlCell = singleXmlCellsMappings.get(xpath);
XSSFTable table = tableMappings.get(xpath);
if (!xpath.matches(".*\\[.*")) {
// Exports elements and attributes mapped with simpleXmlCell
if (simpleXmlCell!=null) {
XSSFCell cell = simpleXmlCell.getReferencedCell();
if (cell!=null) {
Node currentNode = getNodeByXPath(xpath,doc.getFirstChild(),doc,false);
STXmlDataType.Enum dataType = simpleXmlCell.getXmlDataType();
mapCellOnNode(cell,currentNode,dataType);
//remove nodes which are empty in order to keep the output xml valid
if("".equals(currentNode.getTextContent()) && currentNode.getParentNode() != null) {
currentNode.getParentNode().removeChild(currentNode);
}
}
}
// Exports elements and attributes mapped with tables
if (table!=null) {
List<XSSFXmlColumnPr> tableColumns = table.getXmlColumnPrs();
XSSFSheet sheet = table.getXSSFSheet();
int startRow = table.getStartCellReference().getRow();
// In mappings created with Microsoft Excel the first row contains the table header and must be skipped
startRow +=1;
int endRow = table.getEndCellReference().getRow();
for(int i = startRow; i<= endRow; i++) {
XSSFRow row = sheet.getRow(i);
Node tableRootNode = getNodeByXPath(table.getCommonXpath(),doc.getFirstChild(),doc,true);
short startColumnIndex = table.getStartCellReference().getCol();
for(int j = startColumnIndex; j<= table.getEndCellReference().getCol();j++) {
XSSFCell cell = row.getCell(j);
if (cell!=null) {
XSSFXmlColumnPr pointer = tableColumns.get(j-startColumnIndex);
String localXPath = pointer.getLocalXPath();
Node currentNode = getNodeByXPath(localXPath,tableRootNode,doc,false);