Converting an Excel spreadsheet to an XML document
In the previous section an Excel document was generated from an XML document. In this section the Excel document is converted back to an XML document. The Apache POI HSSF API may also be used to parse an Excel spreadsheet and retrieve the cell values from the spreadsheet.
In the ExcelToXML.java application in the XMLExcel project in JDeveloper, import the Apache POI HSSF API.
import org.apache.poi.hssf.usermodel.*;
Creating the XML document
The root element of the XML document that we shall generate is catalog
. We shall add a journal
element to the root element corresponding to each of the rows of the Excel spreadsheet. First, generate an XML document and specify the root element of the document using the JAXP API, which was discussed in Chapter 1.
DocumentBuilderFactory factory =DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.newDocument(); Element catalogElement=document...