XML解析的Andr​​oid code [英] Xml parse android code

查看:105
本文介绍了XML解析的Andr​​oid code的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为Android应用程序,我需要显示的此页:在应用展 Compra =481.3文塔=485,但我不能DOLAR SPOT INTERBANCARIO和Var_por = - 0.53Var_pes = - 2,60霍拉​​=10:35。帮我code吧。

I am making an application for Android and I need to display an XML file of this page: In the application show Compra="481.3" Venta="485" but i cant "DOLAR SPOT INTERBANCARIO" and Var_por="-0,53" Var_pes="-2,60" hora="10:35". Help me with the code please.

XML图像

XML image

这是ExampleHandler code

This is ExampleHandler code

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));
    }
}

}

推荐答案

您可以检查出的SimpleXML的小东西那样。它的工作原理以及在Android上。

You might check out SimpleXML for something small like that. It works well on Android.

SimpleXML的解析器

这篇关于XML解析的Andr​​oid code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆