String xpathString = singleXmlCell.getXpath();
Node result = (Node) xpath.evaluate(xpathString,doc, XPathConstants.NODE);
String textContent = result.getTextContent();
logger.log(POILogger.DEBUG,"Extracting with xpath "+xpathString+" : value is '"+textContent+"'");
XSSFCell cell = singleXmlCell.getReferencedCell();
logger.log(POILogger.DEBUG,"Setting '"+textContent+"' to cell "+cell.getColumnIndex()+"-"+cell.getRowIndex()+" in sheet "+cell.getSheet().getSheetName());
cell.setCellValue(textContent);
}
for(Table table : tables){
String commonXPath = table.getCommonXpath();
NodeList result = (NodeList) xpath.evaluate(commonXPath,doc, XPathConstants.NODESET);
int rowOffset = table.getStartCellReference().getRow()+1;//the first row contains the table header
int columnOffset = table.getStartCellReference().getCol()-1;
for(int i = 0; i< result.getLength();i++){
// TODO: implement support for denormalized XMLs (see OpenOffice part 4: chapter 3.5.1.7)
for(XSSFXmlColumnPr xmlColumnPr: table.getXmlColumnPrs()){
int localColumnId = (int)xmlColumnPr.getId();
int rowId = rowOffset+i;
int columnId = columnOffset+localColumnId;
String localXPath = xmlColumnPr.getLocalXPath();
localXPath = localXPath.substring(localXPath.substring(1).indexOf('/')+1);
// Build an XPath to select the right node (assuming that the commonXPath != "/")
String nodeXPath = commonXPath+"["+(i+1)+"]"+localXPath;
// TODO: convert the data to the cell format
String value = (String) xpath.evaluate(nodeXPath,result.item(i), XPathConstants.STRING);
logger.log(POILogger.DEBUG,"Extracting with xpath "+nodeXPath+" : value is '"+value+"'");
XSSFRow row = table.getXSSFSheet().getRow(rowId);
if(row==null){
row = table.getXSSFSheet().createRow(rowId);
}
XSSFCell cell = row.getCell(columnId);
if(cell==null){
cell = row.createCell(columnId);
}
logger.log(POILogger.DEBUG,"Setting '"+value+"' to cell "+cell.getColumnIndex()+"-"+cell.getRowIndex()+" in sheet "+table.getXSSFSheet().getSheetName());
cell.setCellValue(value.trim());
}