Ola, Pessoal!O codigo abaixo faz a geracao de dados para a MATRIZ DE TRIBUTACAO DO IMPORTADOR, novo servico disponivel no site da Sefaz de alguns estados brasileiros.Este codigo-fonte esta em VISUAL STUDIO 2012 para VB.NET e ja da uma ideia de como gerar o XML para atender aos requesitos da Sefaz. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Try Catch ex As Exception End Try Dim Ano As String = "" Dim Mes As String = "" Dim Dia As String = "" Dim sDataIni As String = Now Dim myConnectionMatrix As MySqlConnection Dim myCommand2IM As MySqlCommand Dim dsR As MySqlDataReader Ano = Trim(Replace(Mid(sDataIni, 7, 4), "/", "")) Mes = Trim(Replace(Mid(sDataIni, 4, 2), "/", "")) Dia = Trim(Replace(Mid(sDataIni, 1, 2), "/", "")) sInicio = Ano + "-" + Mes + "-" + Dia sTimes = CStr(Now) sHora = Mid(sTimes, 12, 8) Dim sDataGeracao As String = Ano + "-" + Mes + "-" + Dia + " " + sHora myConnectionMatrix = New MySqlConnection("server=192.168.40.65; user id=root; password=3007722108; database=orca; pooling=false;") myConnectionMatrix.Open() Dim myCommandsEQ As MySqlCommand Dim sSequencia As String = "" sSQL = "SELECT ifnull(count(sequencial),0) FROM GERARXML" myCommandsEQ = New MySqlCommand(sSQL, myConnectionMatrix) dsR = myCommandsEQ.ExecuteReader If dsR.Read() Then sSequencia = dsR(0) End If dsR.Close() sSequencia = sSequencia + 1 'If Len(sSequencia) = 1 Then ' sNumeroMatrizDi = "0000000000000" + sSequencia ' ElseIf Len(sSequencia) = 2 Then 'sNumeroMatrizDi = "000000000000" + sSequencia 'ElseIf Len(sSequencia) = 3 Then 'sNumeroMatrizDi = "00000000000" + sSequencia 'ElseIf Len(sSequencia) = 4 Then 'sNumeroMatrizDi = "0000000000" + sSequencia 'End If 'Gerar sequencial da XML sSQL = "INSERT INTO GERARXML VALUES(" & CInt(sSequencia) & ",'" & sDataGeracao & "','" & sNumeroMatrizDi & "')" 'Pega os valores das data definidas dentro da tabela padrao myCommand2IM = New MySqlCommand(sSQL, myConnectionMatrix) dsR = myCommand2IM.ExecuteReader dsR.Close() 'Ler os dados sSQL = "SELECT * FROM matriztrib WHERE DATAREGISTRO = '" & sInicio & "' ORDER BY CODPROD" 'Pega os valores das data definidas dentro da tabela padrao myCommand2IM = New MySqlCommand(sSQL, myConnectionMatrix) dsR = myCommand2IM.ExecuteReader Dim sInicioBenf As String = "" Dim sFimBenef As String = "" Dim sImportador As String = "" 'Gerar o XML de cada item 'Abre o Arquivo para Criacao do XML '---------------------------------- 'sNumeroMatrizDi = sNumeroMatrizDi + 1 'Cabecalho do Arquivo '-------------------- Dim sData As String = CStr(Now) Ano = Trim(Replace(Mid(sData, 7, 4), "/", "")) Mes = Trim(Replace(Mid(sData, 4, 2), "/", "")) Dia = Trim(Replace(Mid(sData, 1, 2), "/", "")) sArquivo = "MatrizDI_" + sNumeroMatrizDi + "_" + DateTime.Now.ToString("ddMMyy") + "_" + DateTime.Now.ToString("hhmmss") + ".xml" Dim arq As New StreamWriter("C:\Temp\" + sArquivo, False) 'arq.WriteLine("i" & "<?xml version=" & Chr(34) & "1.0" & Chr(34) & " encoding=" & Chr(34) & "UTF-8" & Chr(34) & "??>") arq.WriteLine("<?xml version=" & Chr(34) & "1.0" & Chr(34) & " encoding=" & Chr(34) & "UTF-8" & Chr(34) & "??>") arq.WriteLine("<enviMatrizDIe xmlns=" & Chr(34) & "http://www.sefaz.am.gov.br/die" & Chr(34) & " xmlns:xsi=" & Chr(34) & "http://www.w3.org/2001/XMLSchema-instance" & Chr(34) & " versao=" & Chr(34) & "1.00" & Chr(34) & " xsi:schemaLocation=" & Chr(34) & "http://www.sefaz.am.gov.br/die enviGabaritoDIe_v1.00.xsd" & Chr(34) & "?>") arq.WriteLine("<MatrizDIe?>") arq.WriteLine("<InfMatrizDIe Id=" & Chr(34) & "MatrizDIe" & sNumeroMatrizDi