我正在爲Android做一個應用程序,我需要顯示一個XML文件this page:在應用程序顯示Compra="481.3" Venta="485"
但我不能"DOLAR SPOT INTERBANCARIO" and Var_por="-0,53" Var_pes="-2,60" hora="10:35"
。請幫助我的代碼。Xml解析android代碼
XML圖像
這是ExampleHandler代碼
public class ExampleHandler extends DefaultHandler {
private boolean in_Root = false;
private boolean in_Registro = false;
private ParsedExampleDataSet myParsedExampleDataSet = new ParsedExampleDataSet();
public ParsedExampleDataSet getParsedData() {
return this.myParsedExampleDataSet;
}
@Override
public void startDocument() throws SAXException {
this.myParsedExampleDataSet = new ParsedExampleDataSet();
}
@Override
public void endDocument() throws SAXException {
}
@Override
public void startElement(String namespaceURI, String localName,
String qName, Attributes atts) throws SAXException {
if (localName.equals("Root")) {
this.in_Root = true;
}else if (localName.equals("Registro")) {
this.in_Registro = true;
// Extract an Attribute
String attrValue = atts.getValue("Compra");
Float compra = Float.parseFloat(attrValue);
myParsedExampleDataSet.setExtractedCompra(compra);
String attrValue2 = atts.getValue("Venta");
Float venta = Float.parseFloat(attrValue2);
myParsedExampleDataSet.setExtractedVenta(venta);
**String attrValue3 = atts.getValue("Var_por");
Float por = Float.parseFloat(attrValue3);
myParsedExampleDataSet.setExtractedPor(por);**
//its my wrong code for Var_por
}
}
@Override
public void endElement(String namespaceURI, String localName, String qName)
throws SAXException {
if (localName.equals("Root")) {
this.in_Root = false;
}else if (localName.equals("Registro")) {
}
}
/** Gets be called on the following structure:
* <tag>characters</tag> */
@Override
public void characters(char ch[], int start, int length) {
if(this.in_Registro){
//myParsedExampleDataSet.setExtractedStruct(new String(ch, start, length));
}
}
}
請參閱[this](http://www.ibm.com/developerworks/opensource/library/x-android/) – 2012-07-27 14:58:35