Olá pessoal,
Tenho um NFe em XML e quero importar para o meu sistema, mas não consigo pegar os dados corretamente, olha como fica a saida do código:
ID= NFe35080599999090910270550010000000015180051273
35 // seria a tag <cUF>35</cUF>
518005127 // seria a tag<cNF>518005127</cNF>
Venda a vista //Não consigo pega-las uma por uma
0
55
1
1
2008-05-06
2008-05-06
0
3550308
1
1
3
2
1
0
NF-eletronica.com...
gostaria de pegar esses dados UM por Um o código usado que usei foi este abaixo:
try {
DocumentBuilderFactory factory =DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse("C:\\NFe_assinada.xml");
NodeList listaDeInfNFe = doc.getElementsByTagName("infNFe");
int tamanhoLista = listaDeInfNFe.getLength();
for(int i=0;i<tamanhoLista; i++){
Node noNFe = listaDeInfNFe.item(i);
if(noNFe.getNodeType()== Node.ELEMENT_NODE){
Element elementoNFe =(Element) noNFe;
String id=elementoNFe.getAttribute("Id");
System.out.println("ID= " + id);
//--------
NodeList listaDeSubTagsDaNFe = elementoNFe.getChildNodes();
int tamanhoListaFilhos = listaDeSubTagsDaNFe.getLength();
for(int j= 0; j<tamanhoListaFilhos;j++){
Node nodeSubTags = listaDeSubTagsDaNFe.item(j);
if(nodeSubTags.getNodeType() == Node.ELEMENT_NODE){
Element elementoSubTag = (Element) nodeSubTags;
switch(elementoSubTag.getTagName()){
case "ide":
System.out.println("cUF= " + elementoSubTag.getTextContent() );
break;
}
}
}
}
}
} catch (ParserConfigurationException | SAXException | IOException ex) {
Logger.getLogger(XML.class.getName()).log(Level.SEVERE, null, ex);
}
Até consigo pegar a TAG <infNFe> mas a partir dai não sei como proceder para pegar por exemplo as TAGs <cUF>,<cNF>,<natOp>e outras para que eu possa inserir no Banco.
por gentileza me ajudem...
<Como importar arquivo XML usando API DOM e pagar os dados UM por UM?>