Nfe marshall

amigos,

quando eu faco um marshall de um xml
ele me gera o xml com o seguinte cabecalho

<?xml version="1.0" encoding="UTF-8" standalone="true"?>

eu quero tirar o standalone=“true” e tambem
tirar o xmlns:ns2"http://www.w3.org/2000/09/xmldsig#"

deve ter alguma propriedade que preciso setar
alguem pode me ajudar

Já tive esse problema.

Segue o post que me ajudou: http://stackoverflow.com/questions/5720501/jaxb-marshalling-xmpp-stanzas

digaoneves
eu vi la
me mandaram colocar

marshaller.setProperty(“com.sun.xml.bind.xmlDeclaration”, Boolean.FALSE);

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)

Olá jonas,

escrevo o XML da minha NF-e desta maneira:

[code]
public String escreveXML(String nomeArq){

    String nomeArquivo = FuncaoValidador.diretorio + File.separator + nomeArq.toLowerCase().replace(".txt", ".xml");
    
    try {
        JAXBContext context = JAXBContext.newInstance(NFe.getClass());
        Marshaller marshaller = context.createMarshaller();
        marshaller.marshal(NFe, new FileWriter(nomeArquivo));
        Marshaller m = context.createMarshaller();
        m.setProperty(Marshaller.JAXB_ENCODING, new String("UTF-8"));
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);


        FileReader fr = new FileReader(new File(nomeArquivo));
        BufferedReader br = new BufferedReader(fr);

        String conteudoXML = "";
        String str = null;

        //Neste ponto vc pode trocar o que vc quizer no seu arquivo
        while ((str = br.readLine()) != null) {
            str = str.replace("ns2:", "");
            str = str.replace(":ns2", "");
            conteudoXML += str;
        }

        FileWriter fw = new FileWriter(new File(nomeArquivo));
        BufferedWriter bw = new BufferedWriter(fw);

        bw.write(conteudoXML);
        bw.flush();
        bw.close();

        br.close();

        return "";
        
    } catch (JAXBException e) {
        e.printStackTrace();
        return "Não foi possível converter a nota para XML"+"\n"+"Descrição do erro: "+e.getMessage();
    } catch (IOException e) {
        e.printStackTrace();
        return "Não foi possível escrever a nota em XML"+"\n"+"Descrição do erro: "+e.getMessage();
    } catch (Exception e) {
        e.printStackTrace();
        return "Não foi possível transformar o arquivo TXT da nota em XML"+"\n"+"Descrição do erro: "+e.getMessage();
    }

}[/code]

Espero ter ajudado

Até

[quote=jonasjgs2]digaoneves
eu vi la
me mandaram colocar

marshaller.setProperty(“com.sun.xml.bind.xmlDeclaration”, Boolean.FALSE);

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)
[/quote]
Dependendo da sua versão do JAXB essas propriedades vão mudar, você tem que ver como fica para a versão que está usando.