0
我想從下面的xml中提取數據。率&貨幣工作正常,但我不能提取時間。從xml中提取數據的問題
<Cube>
<Cube time='2011-04-15'>
<Cube currency='USD' rate='1.4450'/>
<Cube currency='JPY' rate='120.37'/>
</Cube>
中的startElement方法中的代碼
if (localName.equals("Cube")) {
for (int i = 0; i < attributes.getLength(); i++) {
if ((attributes.getLocalName(i)).equals("currency")) {
name = attributes.getValue(i);
} else if ((attributes.getLocalName(i)).equals("time")) {
date = attributes.getValue(i);
}
else if ((attributes.getLocalName(i)).equals("rate")) {
try {
rate = Double.parseDouble(attributes.getValue(i));
} catch (Exception e) {
}
這可能對你有幫助。 http://stackoverflow.com/questions/4827344/how-to-parse-xml-using-the-sax-parser/4828765#4828765 – 2011-04-18 13:00:33