Ler arquivo Xml

1 resposta
E

Tenho o seguinte xml :

<ans:mensagemTISS xsi:schemaLocation="http://www.ans.gov.br/padroes/tiss/schemas http://www.ans.gov.br/padroes/tiss/schemas/tissV3_00_01.xsd"><ans:cabecalho><ans:identificacaoTransacao><ans:tipoTransacao>ENVIO_LOTE_GUIAS</ans:tipoTransacao><ans:sequencialTransacao>236</ans:sequencialTransacao><ans:dataRegistroTransacao>2013-07-22</ans:dataRegistroTransacao><ans:horaRegistroTransacao>16:16:30</ans:horaRegistroTransacao></ans:identificacaoTransacao><ans:origem><ans:identificacaoPrestador><ans:codigoPrestadorNaOperadora>999888777</ans:codigoPrestadorNaOperadora></ans:identificacaoPrestador></ans:origem>

Fiz a seguinte rotina : 

      SAXBuilder builder = new SAXBuilder();
        File xmlFile = new File("c:/evandro/AMB1.xml");

        try {

            Document document = (Document) builder.build(xmlFile);
            Element rootNode = document.getRootElement();
            List list = rootNode.getChildren("cabecalho");

            for (int i = 0; i < list.size(); i++) {

                Element node = (Element) list.get(i);

                System.out.println("First Name : " + node.getChildText("ans:tipoTransacao"));
            }

        } catch (IOException io) {
            System.out.println(io.getMessage());
        } catch (JDOMException jdomex) {
            System.out.println(jdomex.getMessage());
        }

A lista esta vindo 0, não esta encontrando o  cabeçalho.

Obs. estou usando o Jdom, o xml esta incompleto pois ele é grande

1 Resposta

aix

altere este linha

List list = rootNode.getChildren("cabecalho");

por

List list = rootNode.getContent();
Criado 24 de julho de 2013
Ultima resposta 25 de jul. de 2013
Respostas 1
Participantes 2