我正在使用DOM解析器来解析输入xml,如下所示,然后在excel的各个单元格中设置值。
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(inputstream);
NodeList nodelist = document.getElementsByTagName("ExchangeRate");
请让我知道如何添加;在从xml获取的不同值之间。
HSSFRow row1 = ITSFX.createRow(1);
cell = row1.createCell((short) 0);
cell.setCellValue(((Element) (nodelist.item(0))).getElementsByTagName("CurrencyFrom").item(0). getFirstChild() .getNodeValue());
在这种情况下,我从xml中获取了第一个值,即EUR。
现在,我必须使用半冒号作为分隔符,在同一单元格[1,0]中添加xml中的第二个值。 inputXML
<?xml version="1.0" encoding="UTF-8"?>
<incmstmts>
<ExchangeRate>
<CurrencyFrom>EUR</CurrencyFrom>
<CurrencyTo>AUD</CurrencyTo>
<Date>30.04.2019</Date>
<ConversionType>1</ConversionType>
<Value>5911</Value>
</ExchangeRate>
<ExchangeRate>
<CurrencyFrom>EUR</CurrencyFrom>
<CurrencyTo>BRL</CurrencyTo>
<Date>30.04.2019</Date>
<ConversionType>1</ConversionType>
<Value>405</Value>
</ExchangeRate>
<ExchangeRate>
<CurrencyFrom>EUR</CurrencyFrom>
<CurrencyTo>BGN</CurrencyTo>
<Date>30.04.2019</Date>
<ConversionType>1</ConversionType>
<Value>9558</Value>
</ExchangeRate>
</incmstmts>
EUR; AUD; 30.04.2019; 1 5911
EUR; BRL; 30.04.2019; 4405