Skip to content

Instantly share code, notes, and snippets.

@gerep
Last active March 17, 2016 02:06
Show Gist options
  • Select an option

  • Save gerep/1956e4352e737193c09b to your computer and use it in GitHub Desktop.

Select an option

Save gerep/1956e4352e737193c09b to your computer and use it in GitHub Desktop.
package main
import (
"encoding/xml"
"fmt"
)
//<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
type Envelope struct {
XMLName xml.Name `xml:"soap12:Envelope"`
XMLnsXsi string `xml:"xmlns:xsi,attr"`
XMLnsXsd string `xml:"xmlns:xsd,attr"`
XMLnsSoap12 string `xml:"xmlns:soap12,attr"`
Cabecalho Cabecalho
}
//<soap12:Header>
type Cabecalho struct {
XMLName xml.Name `xml:"soap12:Header"`
NFeCabecalhoMensagem NFeCabecalhoMensagem
}
//<nfeCabecMsg xmlns="https://homologacao.nfe.fazenda.sp.gov.br/ws/recepcaoevento.asmx">
type NFeCabecalhoMensagem struct {
XMLName xml.Name `xml:"nfeCabecMsg"`
XMLns string `xml:"xmlns,attr"`
CUF int `xml:"cUF"`
VersaoDados float32 `xml:"versaoDados"`
CampoOpcional string `xml:"opcional,omitempty"`
Comentario string `xml:",comment"`
}
func main() {
env := Envelope{XMLnsXsi: "http://www.w3.org/2001/XMLSchema-instance", XMLnsXsd: "http://www.w3.org/2001/XMLSchema", XMLnsSoap12: "http://www.w3.org/2003/05/soap-envelope"}
env.Cabecalho = Cabecalho{NFeCabecalhoMensagem: NFeCabecalhoMensagem{XMLns: "https://homologacao.nfe.fazenda.sp.gov.br/ws/recepcaoevento.asmx", CUF: 35, VersaoDados: 3.0, Comentario: "NF-E EMITIDA EM AMBIENTE DE HOMOLOGACAO – SEM VALOR FISCAL"}}
data, err := xml.MarshalIndent(env, " ", " ")
if err != nil {
fmt.Println(err)
}
fmt.Printf("%s\n", data)
}
//<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
// <soap12:Header>
// <nfeCabecMsg xmlns="https://homologacao.nfe.fazenda.sp.gov.br/ws/recepcaoevento.asmx">
// <cUF>35</cUF>
// <versaoDados>3.10</versaoDados>
// </nfeCabecMsg>
// </soap12:Header>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment