I have the following code to parse an xml script below
class Cell {
string data;
}
Integer rowCounter = 0;
List<Cell> cells = new List<Cell>();
Map<Integer, List<Cell>> timeEntryMap = new Map<Integer, List<Cell>>();
//See the xmloutput after this apex codes.
XmlStreamReader xsr = new XmlStreamReader(xmlOutput);
while(xsr.hasNext())
{
if(xsr.getEventType() == XmlTag.START_ELEMENT) {
if(xsr.getLocalName() == 'Row') {
rowCounter++;
timeEntryMap.put(rowCounter, cells);
cells = new List<Cell>();
}
if (xsr.getLocalName() == 'Cell') {
Cell cell = getCellData(xsr);
cells.add(cell);
}
}
xsr.next();
}
Cell getCellData(XmlStreamReader reader) {
string dataContainer = '';
Cell cell = new Cell();
while(reader.hasNext()){
if (reader.getEventType() == XmlTag.END_ELEMENT)
break;
else if (reader.getEventType() == XmlTag.CHARACTERS){
if (!String.isBlank(reader.getText())){
dataContainer += reader.getText();
}
}
reader.next();
}
cell.data = dataContainer;
return cell;
}
for (Integer key : timeEntryMap.keySet()){
system.debug('===============ROW Start====================');
for (Integer i = 0;i < timeEntryMap.get(key).size();i++){
system.debug(timeEntryMap.get(rowKey)[i].data);
}
system.debug('===============ROW End====================');
}
Here is the xmlOutput that I am trying to parse..
<Table>
<Row>
<Cell ss:StyleID="Default">
<Data ss:Type="String">19c46fb7-5314-4f8d-b6b5...</Data>
</Cell>
<Cell ss:StyleID="Date">
<Data ss:Type="DateTime">2016-06-07T00:00:00</Data>
</Cell>
<Cell ss:StyleID="Date">
<Data ss:Type="DateTime">2016-06-05T00:00:00</Data>
</Cell>
<Cell ss:StyleID="Date">
<Data ss:Type="DateTime">2016-06-11T00:00:00</Data>
</Cell>
<Cell ss:StyleID="Default">
<Data ss:Type="String">urn:tenant:user...</Data>
</Cell>
<Cell ss:StyleID="Number">
<Data ss:Type="Number">2.00</Data>
</Cell>
<Cell ss:StyleID="Number">
<Data ss:Type="Number">0.00</Data>
</Cell>
</Row>
<Row>
<Cell ss:StyleID="Default">
<Data ss:Type="String">19c46fb7-5314-4f8d-b6b5...</Data>
</Cell>
<Cell ss:StyleID="Date">
<Data ss:Type="DateTime">2016-06-10T00:00:00</Data>
</Cell>
<Cell ss:StyleID="Date">
<Data ss:Type="DateTime">2016-06-05T00:00:00</Data>
</Cell>
<Cell ss:StyleID="Date">
<Data ss:Type="DateTime">2016-06-11T00:00:00</Data>
</Cell>
<Cell ss:StyleID="Default">
<Data ss:Type="String">urn:tenant:user...</Data>
</Cell>
<Cell ss:StyleID="Number">
<Data ss:Type="Number">2.00</Data>
</Cell>
<Cell ss:StyleID="Number">
<Data ss:Type="Number">0.00</Data>
</Cell>
</Row>
</Table>
This maybe somehow similar to this issue.
Was this really an issue with XmlStreamReader
so the only way to get this thing to work is to use XML Dom Reader
? I am taking the XML Dom reader
as my last resort if this could not really get to work with XmlStreamReader