0
I am developing a Java application that I will need to extract XML data from Nfe,
Extract some data I can map the Tags as issuer recipient among others.
But when I need to extract products from Nfe I cannot.
Below is a product snippet from an Nfe XML.
nfe.xml
<det nItem="1">
<prod>
<cProd>121402233</cProd>
<cEAN>7898950236241</cEAN>
<xProd>Michaelis Dicionario Escolar Da Lingua Portuguesa 1a Ed</xProd>
<NCM>49019900</NCM>
<CFOP>5102</CFOP>
<uCom>PC</uCom>
<qCom>1</qCom>
<vUnCom>32.90</vUnCom>
<vProd>32.90</vProd>
<cEANTrib>7898950236241</cEANTrib>
<uTrib>PC</uTrib>
<qTrib>1</qTrib>
<vUnTrib>32.90</vUnTrib>
<vFrete>3.95</vFrete>
<vDesc>3.95</vDesc>
<indTot>1</indTot>
</prod>
<imposto>
<ICMS>
<ICMS40>
<orig>0</orig>
<CST>40</CST>
</ICMS40>
</ICMS>
<PIS>
<PISNT>
<CST>06</CST>
</PISNT>
</PIS>
<COFINS>
<COFINSNT>
<CST>06</CST>
</COFINSNT>
</COFINS>
</imposto>
<infAdProd>Desconto Incondicional Concedido: R$ 3.95</infAdProd>
</det>
Below is an excerpt from the code that reads a field(tag) of Nfe.
Leituraxml.java
public class LeituraXml {
private SAXBuilder sb;
private Document d;
private Element nfe;
public LeituraXml(String arquivo) {
try {
sb = new SAXBuilder();
d = sb.build(new File(arquivo));
nfe = d.getRootElement();
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "Exceção ao processar arquivo! " + e.getMessage());
}
}
public String getNumeroNFe() {
try {
XPath nNF = XPath.newInstance("//k:nfeProc/k:NFe/k:infNFe/k:ide/k:nNF");
nNF.addNamespace("k", d.getRootElement().getNamespaceURI());
Element node = (Element) nNF.selectSingleNode(d.getRootElement());
return node.getText();
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "Erro ao processar arquivo! " + e.getMessage());
return null;
}
}
}
What is the purpose of transforming XSD files into XML files?
– TGO