mas me da um erro nesta linha e eu ja to ficando louco…rs
javax.xml.bind.PropertyException: name: com.sun.xml.bind.xmlDeclaration value: false
at javax.xml.bind.helpers.AbstractMarshallerImpl.setProperty(AbstractMarshallerImpl.java:338)
A
AlanRS
Olá jonas,
escrevo o XML da minha NF-e desta maneira:
publicStringescreveXML(StringnomeArq){StringnomeArquivo=FuncaoValidador.diretorio+File.separator+nomeArq.toLowerCase().replace(".txt",".xml");try{JAXBContextcontext=JAXBContext.newInstance(NFe.getClass());Marshallermarshaller=context.createMarshaller();marshaller.marshal(NFe,newFileWriter(nomeArquivo));Marshallerm=context.createMarshaller();m.setProperty(Marshaller.JAXB_ENCODING,newString("UTF-8"));m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,true);FileReaderfr=newFileReader(newFile(nomeArquivo));BufferedReaderbr=newBufferedReader(fr);StringconteudoXML="";Stringstr=null;//Neste ponto vc pode trocar o que vc quizer no seu arquivowhile((str=br.readLine())!=null){str=str.replace("ns2:","");str=str.replace(":ns2","");conteudoXML+=str;}FileWriterfw=newFileWriter(newFile(nomeArquivo));BufferedWriterbw=newBufferedWriter(fw);bw.write(conteudoXML);bw.flush();bw.close();br.close();return"";}catch(JAXBExceptione){e.printStackTrace();return"Não foi possível converter a nota para XML"+"\n"+"Descrição do erro: "+e.getMessage();}catch(IOExceptione){e.printStackTrace();return"Não foi possível escrever a nota em XML"+"\n"+"Descrição do erro: "+e.getMessage();}catch(Exceptione){e.printStackTrace();return"Não foi possível transformar o arquivo TXT da nota em XML"+"\n"+"Descrição do erro: "+e.getMessage();}}