如何将具有向量的XML解析为另一个向量?

时间:2016-11-11 15:59:06

标签: java android xml ksoap2

我对如何解析服务器发送给我的XML有一些疑问。我可以获取数据直到Cobranca标记,但之后,它会向我发送一个我无法获取的数据。这是代码的一部分。

的xml:

 <return xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="tns:DebitosPendentes[19]">
                <item xsi:type="tns:DebitosPendentes">
                    <Vencimento xsi:type="xsd:string">2016-05-07</Vencimento>
                    <ValorAtualizado xsi:type="xsd:decimal">102.00</ValorAtualizado>
                    <Valor xsi:type="xsd:decimal">100.00</Valor>
                    <Sequencia xsi:type="xsd:string">182</Sequencia>
                    <NroBanco xsi:type="xsd:int">39</NroBanco>
                    <BcoCobr xsi:type="xsd:int">237</BcoCobr>
                    <Cobranca xsi:type="xsd:string">S</Cobranca>
                    <Itens xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="tns:ListaItens[1]">
                        <item xsi:type="tns:ListaItens">
                            <Descricao xsi:type="xsd:string">COBR ws</Descricao>
                            <ValorItem xsi:type="xsd:decimal">100.00</ValorItem>
                        </item>
                    </Itens>
                </item>

代码java

public  void buscaDebitosPendentes(int codigoCliente){


        SoapObject request = new SoapObject("urn:RouterBoxMobile","BuscarDebitosPendentes");

        SoapObject chaveIntegracao = new SoapObject("urn:RouterBoxMobile","BuscarDebitosPendentes");
        chaveIntegracao.addProperty("ChaveIntegracao",chaveDeIntegracao);
        request.addProperty("Autenticacao",chaveIntegracao);

        SoapObject codigo = new SoapObject("urn:RouterBoxMobile","BuscarDebitosPendentes");

        codigo.addProperty("CodigoCliente",codigoCliente);

        request.addProperty("DadosDebitosPendentes",codigo);
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.setOutputSoapObject(request);
        envelope.implicitTypes=true;

        HttpTransportSE httpTransportSE = new HttpTransportSE(URL_WEBSERVICE);

         httpTransportSE.debug=true;

        try {
            httpTransportSE.call("",envelope);

            Log.d("Request",httpTransportSE.requestDump.toString());
            Log.d("Response",httpTransportSE.responseDump.toString());


           @SuppressWarnings("unchecked")
            Vector<Object> vector = (Vector<Object>) envelope.getResponse();

            Log.d("Response in SOAP",vector.toString());

            for (int i=0; i< vector.size();i++){
                SoapObject object = (SoapObject) vector.get(i);
                if (object!=null){
                    Log.d("Vencimento",object.getProperty("Vencimento").toString());
                    Log.d("Sequencia",object.getProperty("Sequencia").toString());
                    Log.d("Descricao",object.getProperty("Descricao").toString());


                }
            }

        } catch (IOException e) {
            e.printStackTrace();
        } catch (XmlPullParserException e) {
            e.printStackTrace();
        }

    }

1 个答案:

答案 0 :(得分:0)

我能够解决以下问题,我得到xml数组的位置,然后我去了一个向量。  请遵循以下代码:

{{1}}