Olá Joca,
bom cara … acho que vc tem um longo caminho então …
vc já fez as classes que determinam as variaveis que vc precisará colocar na NFe?
no seu manual vai ter os grupos A, B, C… essas classes tem que ser feitas.
aqui vai o exemplo da minha classe do grupo A para seu melhor entendimento:
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
/*
* GRUPO DAS INFORMAÇÕES DA NF-e
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "infNFe")
public class A {
@XmlAttribute
private String versao; //Versão do Leiaute
@XmlAttribute(name = "Id")
private String Id; //Identificador da NFe
private String chaveNfe; //Variavel passada para auxiliar na construção do registro.
private B ide;
private C emit;
private D avulsa; //Não utilizar
private E dest;
private F retirada;
private G entrega;
private List<H> det;
private W total;
private X transp;
private Y cobr;
private Z infAdic;
private ZA exporta;
private ZB compra;
private ZC cana;
/**********GETTERS**********/
public String getId() {
return Id;
}
public String getVersao() {
return versao;
}
public String getChaveNfe() {
return chaveNfe;
}
public B getIde() {
return ide;
}
public C getEmit() {
return emit;
}
public D getAvulsa() {
return avulsa;
}
public E getDest() {
return dest;
}
public F getRetirada() {
return retirada;
}
public G getEntrega() {
return entrega;
}
public List<H> getDet() {
return det;
}
public W getTotal() {
return total;
}
public X getTransp() {
return transp;
}
public Y getCobr() {
return cobr;
}
public Z getInfAdic() {
return infAdic;
}
public ZA getExporta() {
return exporta;
}
public ZB getCompra() {
return compra;
}
public ZC getCana() {
return cana;
}
/**********SETTERS**********/
public void setId(String Id) {
this.Id = Id;
}
public void setVersao(String versao) {
this.versao = versao;
}
public void setChaveNfe(String chaveNfe) {
this.chaveNfe = chaveNfe;
}
public void setIde(B ide) {
this.ide = ide;
}
public void setEmit(C emit) {
this.emit = emit;
}
public void setAvulsa(D avulsa) {
this.avulsa = avulsa;
}
public void setDest(E dest) {
this.dest = dest;
}
public void setRetirada(F retirada) {
this.retirada = retirada;
}
public void setEntrega(G entrega) {
this.entrega = entrega;
}
public void setDet(List<H> det) {
this.det = det;
}
public void setTotal(W total) {
this.total = total;
}
public void setTransp(X transp) {
this.transp = transp;
}
public void setCobr(Y cobr) {
this.cobr = cobr;
}
public void setInfAdic(Z infAdic) {
this.infAdic = infAdic;
}
public void setExporta(ZA exporta) {
this.exporta = exporta;
}
public void setCompra(ZB compra) {
this.compra = compra;
}
public void setCana(ZC cana) {
this.cana = cana;
}
/**********TOSTRING**********/
@Override
public String toString(){
return "A"+"|"
+getVersao()+"|"
+"NFe"+getChaveNfe();
}
}
utilizei a biblioteca do xerces na versao 2.11.0 para desenvolver minha solução
perceba que na classe existem anotações … as quais serão usadas para gerar seu xml…
bom … após o desenvolvimento dos blocos de informações vc tera que preenche-los com as informações e após esse preenchimento vc poderá transformar seu objeto em um arquivo xml com a seguinte função:
public synchronized File escreveNota(Connection c, PedidoVenda pv, Compra compra, String caminhoCertificado, String senha){
try {
File arquivoXml = new File(nomeArquivoCompleto);
JAXBContext context = JAXBContext.newInstance(NFe.getClass());
Marshaller marshaller = context.createMarshaller();
marshaller.marshal(NFe, new FileWriter(arquivoXml));
Marshaller m = context.createMarshaller();
m.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
FileReader fr = new FileReader(arquivoXml);
BufferedReader br = new BufferedReader(fr);
String conteudoXML = "";
String str = null;
while((str = br.readLine()) != null){
str = str.replace("ns2:", "");
str = str.replace(":ns2", "");
conteudoXML += str;
}
FileWriter fw = new FileWriter(arquivoXml);
BufferedWriter bw = new BufferedWriter(fw);
bw.write(conteudoXML);
bw.flush();
bw.close();
br.close();
return arquivoXml;
} catch (JAXBException ex) {
Logger.getLogger(FuncaoCarregarNFe.class.getName()).log(Level.SEVERE, null, ex);
return null;
} catch (IOException ex) {
Logger.getLogger(FuncaoCarregarNFe.class.getName()).log(Level.SEVERE, null, ex);
return null;
} catch (Exception ex) {
Logger.getLogger(FuncaoCarregarNFe.class.getName()).log(Level.SEVERE, null, ex);
return null;
}
}
sei que há outras soluções e esta talvez não seja a melhor … mas esta é a que me atende
espero ter ajudado!