| Exibir mensagem anterior :: Exibir próxima mensagem |
| Autor |
Mensagem |
poolpay Novato

Registrado: Sábado, 17 de Junho de 2017 Mensagens: 7
|
Enviada: Sáb Jun 17, 2017 10:49 am Assunto: Geração de Arquivo XML com componente XMLDocument |
|
|
bom dia !!!!!
Estou gerando um arquivo xml com componente xmldocument esta saindo um atributo que não deveria sair não estou conseguindo acertar isso
<xml>
<Fi:Fundos
xmlns="http://www.teste.com.br"
xmlns:fi="htttp://"www.teste.com.br">
{descritor xmlns=""}
sai esse atributo quando não deveria |
|
| Voltar ao Topo |
|
 |
imex Moderador

Registrado: Sexta-Feira, 7 de Janeiro de 2011 Mensagens: 11666
|
Enviada: Sáb Jun 17, 2017 3:16 pm Assunto: |
|
|
Boa tarde,
Você pode postar o código que você está utilizando para gerar o XML e o trecho exato onde esse atributo está? Esse atributo está entre chaves?
Editado pela última vez por imex em Dom Out 01, 2023 4:11 pm, num total de 1 vez |
|
| Voltar ao Topo |
|
 |
poolpay Novato

Registrado: Sábado, 17 de Junho de 2017 Mensagens: 7
|
Enviada: Sáb Jun 17, 2017 7:39 pm Assunto: Geração de Arquivo XML com componente XMLDocument |
|
|
Codigo para geração
{XMLDocument1.FileName := ''; }
{XMLDocument1.XML.Text := ''; }
{XMLDocument1.Active := False; }
{XMLDocument1.Active := True; }
{XMLDocument1.Version := '1.0'; }
{XMLDocument1.Encoding := 'ISO-8859-1'; }
{ }
{Cabecalho := XMLDocument1.AddChild('fi:FundosInvestimento'); }
{Cabecalho.Attributes['xmlns']:='http://www.tce.sp.gov.br/audesp/xml/fundosinvestimento'; }
{Cabecalho.Attributes['xmlns:xsi']:='http://www.w3.org/2001/XMLSchema-instance'; }
{Cabecalho.Attributes['xmlns:gen']:='http://www.tce.sp.gov.br/audesp/xml/generico'; }
{Cabecalho.Attributes['xmlns:fi']:='http://www.tce.sp.gov.br/audesp/xml/fundosinvestimento'; }
{Cabecalho.Attributes['xsi:schemaLocation']:='http://www.tce.sp.gov.br/audesp/xml/fundosinvestimento ./fundosinvestimento/AUDESP_FUNDOS_INVESTIMENTO_2017_A.XSD';}
{ }
{descritormov:= XMLDocument1.CreateNode('Descritor', ntElement); }
{Cabecalho.ChildNodes.Add(descritormov); }
Arquivo XML Gerado
{?xml version="1.0" encoding="ISO-8859-1"?}
{fi:FundosInvestimento xmlns="http://www.tce.sp.gov.br/audesp/xml/fundosinvestimento" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:gen="http://www.tce.sp.gov.br/audesp/xml/generico" xmlns:fi="http://www.tce.sp.gov.br/audesp/xml/fundosinvestimento" xsi:schemaLocation="http://www.tce.sp.gov.br/audesp/xml/fundosinvestimento ./fundosinvestimento/AUDESP_FUNDOS_INVESTIMENTO_2017_A.XSD"}
{Descritor xmlns=""} |
|
| Voltar ao Topo |
|
 |
poolpay Novato

Registrado: Sábado, 17 de Junho de 2017 Mensagens: 7
|
Enviada: Sáb Jun 17, 2017 7:54 pm Assunto: Geração de Arquivo XML com componente XMLDocument |
|
|
Imex nota-se que na tag Descritor sai xmlns quando não deveria, achei um post que o Jony walker colocou era o mesmo problema.
Ele resolveu da Seguinte maneira:
xmldoc := TXMLDocument.Create(Application);
xmldoc.FileName := '';
xmldoc.XML.Text := '';
xmldoc.Active := False;
xmldoc.Active := True;
xmldoc.Version := '1.0';
xmldoc.Encoding := 'UTF-8';
// Criando a RAIZ
Raiz := xmldoc.AddChild('consSitNFe', 'http://www.portalfiscal.inf.br/nfe');
// Criacao do Node "versao"
xmldoc.ChildNodes['consSitNFe'].Attributes['versao'] := '2.00';
O problema é que no meu quando faço isso ele assume o prefixo do fi e fica assim :
Código Delphi:
{XMLDocument1.FileName := ''; }
{XMLDocument1.XML.Text := ''; }
{XMLDocument1.Active := False; }
{XMLDocument1.Active := True; }
{XMLDocument1.Version := '1.0'; }
{XMLDocument1.Encoding := 'ISO-8859-1'; }
{ }
{Cabecalho := XMLDocument1.AddChild('fi:FundosInvestimento','http://www.tce.sp.gov.br/audesp/xml/fundosinvestimento');
Arquivo Gerado:
{fi:FundosInvestimentos xmlns:fi='http://www.tce.sp.gov.br/audesp/xml/fundosinvestimento'}
Nota-se que ele assumiu o prefico fi: quando não deveria |
|
| Voltar ao Topo |
|
 |
poolpay Novato

Registrado: Sábado, 17 de Junho de 2017 Mensagens: 7
|
Enviada: Dom Jun 18, 2017 9:15 am Assunto: Geração de Arquivo XML com componente XMLDocument |
|
|
Não entendi a pergunta se esta entre chaves mas se for isso que estou pensando ja coloquei veja abaixo:
Var cabecalho{fi:FundosInvestimentos},...
sem sucesso esta a mesma coisa |
|
| Voltar ao Topo |
|
 |
imex Moderador

Registrado: Sexta-Feira, 7 de Janeiro de 2011 Mensagens: 11666
|
Enviada: Dom Jun 18, 2017 7:04 pm Assunto: |
|
|
Perguntei sobre as chaves porque você postou que o XML gerado ficou por exemplo da seguinte forma:
{Descritor xmlns=""}
Colocou o nó Descritor entre chaves, e depois fez a mesma coisa ao postar o código utilizado, só que nesse caso o código viraria um comentário, nem seria executado.
Voltando ao problema, não sei sei entendi corretamente, mas experimente fazer uns testes mais ou menos dessa forma:
| Código: | procedure TForm1.Button1Click(Sender: TObject);
var
XMLDocument1: IXmlDocument;
begin
XMLDocument1 := TXMLDocument.Create(nil);
with XMLDocument1 do
begin
Active := True;
Version := '1.0';
Encoding := 'ISO-8859-1';
DocumentElement := CreateNode('fi:FundosInvestimento', ntElement);
with DocumentElement do
begin
Attributes['xmlns'] := 'http://www.tce.sp.gov.br/audesp/xml/fundosinvestimento';
Attributes['xmlns:xsi'] := 'http://www.w3.org/2001/XMLSchema-instance';
Attributes['xmlns:gen'] := 'http://www.tce.sp.gov.br/audesp/xml/generico';
Attributes['xmlns:fi'] := 'http://www.tce.sp.gov.br/audesp/xml/fundosinvestimento';
Attributes['xsi:schemaLocation'] := 'http://www.tce.sp.gov.br/audesp/xml/fundosinvestimento ./fundosinvestimento/AUDESP_FUNDOS_INVESTIMENTO_2017_A.XSD';
with AddChild('Descritor') do
begin
Text := 'abc';
end;
end;
SaveToFile('C:\Sua_Pasta\Seu_Xml.xml');
end;
end; |
Espero que ajude |
|
| Voltar ao Topo |
|
 |
poolpay Novato

Registrado: Sábado, 17 de Junho de 2017 Mensagens: 7
|
Enviada: Seg Jun 19, 2017 7:35 pm Assunto: Geração de Arquivo XML com componente XMLDocument |
|
|
Imex fiz o que você me disse
mas ainda estou com um problema veja abaixo o código e o arquivo gerado se puder me ajudar
desconsidere as chaves
Código
with XMLDocument1 do
begin
FileName := '';
XML.Text := '';
Active := False;
Active := True;
Version := '1.0';
Encoding := 'ISO-8859-1';
DocumentElement:=CreateNode('fi:FundosInvestimento',ntElement);
with DocumentElement do
begin
Attributes['xmlns']:='http://www.tce.sp.gov.br/audesp/xml/fundosinvestimento';
Attributes['xmlns:xsi']:='http://www.w3.org/2001/XMLSchema-instance';
Attributes['xmlns:gen']:='http://www.tce.sp.gov.br/audesp/xml/generico';
Attributes['xmlns:fi']:='http://www.tce.sp.gov.br/audesp/xml/fundosinvestimento';
Attributes['xsi:schemaLocation']:='http://www.tce.sp.gov.br/audesp/xml/fundosinvestimento ./fundosinvestimento/AUDESP_CADASTRO_FUNDOS_INVESTIMENTO_2017_A.XSD';
with AddChild('Descritor') do
begin
anoexerciciomov := XMLDocument1.CreateNode('gen:AnoExercicio', ntElement);
anoexerciciomov.NodeValue:=anomov;
ChildNodes.Add(anoexerciciomov);
tipodocumentomov := XMLDocument1.CreateNode('gen:TipoDocumento', ntElement);
tipodocumentomov.NodeValue:='Fundos de Investimento';
ChildNodes.Add(tipodocumentomov);
entidademov := XMLDocument1.CreateNode('gen:Entidade', ntElement);
entidademov.NodeValue:=Edit5.Text;
ChildNodes.Add(entidademov);
municipiomov := XMLDocument1.CreateNode('gen:Municipio', ntElement);
municipiomov.NodeValue:=Edit1.Text;
ChildNodes.Add(municipiomov);
datacriacaoxmlmov := XMLDocument1.CreateNode('gen:DataCriacaoXML', ntElement);
datacriacaoxmlmov.NodeValue:=FormatDateTime('yyyy-mm-dd',(date));;
ChildNodes.Add(datacriacaoxmlmov);
mesexerciciomov := XMLDocument1.CreateNode('gen:MesExercicio', ntElement);
mesexerciciomov.NodeValue:=mesmov;
ChildNodes.Add(mesexerciciomov);
end;
with AddChild('FundoInvestimento') do
begin
Codigo := XMLDocument1.CreateNode('Codigo', ntElement);
Codigo.NodeValue:=TbMovFundoTempCODIGOFUNDO.Text;
ChildNodes.Add(Codigo);
end;
end;
Arquivo Gerado
{?xml version="1.0" encoding="ISO-8859-1"?>}
{fi:FundosInvestimento
xmlns="http://www.tce.sp.gov.br/audesp/xml/fundosinvestimento"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:gen="http://www.tce.sp.gov.br/audesp/xml/generico"
xmlns:fi="http://www.tce.sp.gov.br/audesp/xml/fundosinvestimento"
xsi:schemaLocation="http://www.tce.sp.gov.br/audesp/xml/fundosinvestimento ./fundosinvestimento/AUDESP_CADASTRO_FUNDOS_INVESTIMENTO_2017_A.XSD">
{fi:Descritor}
{gen:AnoExercicio}>2017{/gen:AnoExercicio}
{/fi:Descritor}
{fi:FundoInvestimento}
{Codigo xmlns=""}2{/Codigo}
{/fi:FundoInvestimento}
{/fi:FundosInvestimento}
Substitui os > por } porque no site não aceitava
Nota se que no codigo esta saindo ainda aquele xmlns
tem alguma sugestão??? |
|
| Voltar ao Topo |
|
 |
imex Moderador

Registrado: Sexta-Feira, 7 de Janeiro de 2011 Mensagens: 11666
|
Enviada: Seg Jun 19, 2017 8:42 pm Assunto: |
|
|
Experimente fazer uns testes para ver se o XML fica da forma esperada:
| Código: | with XMLDocument1 do
begin
Active := True;
Version := '1.0';
Encoding := 'ISO-8859-1';
DocumentElement:=CreateNode('fi:FundosInvestimento',ntElement);
with DocumentElement do
begin
Attributes['xmlns']:='http://www.tce.sp.gov.br/audesp/xml/fundosinvestimento';
Attributes['xmlns:xsi']:='http://www.w3.org/2001/XMLSchema-instance';
Attributes['xmlns:gen']:='http://www.tce.sp.gov.br/audesp/xml/generico';
Attributes['xmlns:fi']:='http://www.tce.sp.gov.br/audesp/xml/fundosinvestimento';
Attributes['xsi:schemaLocation']:='http://www.tce.sp.gov.br/audesp/xml/fundosinvestimento ./fundosinvestimento/AUDESP_CADASTRO_FUNDOS_INVESTIMENTO_2017_A.XSD';
with AddChild('Descritor') do
begin
with AddChild('gen:AnoExercicio') do
Text := anomov;
with AddChild('gen:TipoDocumento') do
Text := 'Fundos de Investimento';
with AddChild('gen:Entidade') do
Text := Edit5.Text;
with AddChild('gen:Municipio') do
Text := Edit1.Text;
with AddChild('gen:DataCriacaoXML') do
Text := FormatDateTime('yyyy-mm-dd', date);
with AddChild('gen:MesExercicio') do
Text := mesmov;
end;
with AddChild('FundoInvestimento') do
begin
with AddChild('Codigo') do
Text := TbMovFundoTempCODIGOFUNDO.Text;
end;
end;
end; |
obs: para evitar problemas com o sinal de menor e maior no fórum marque o CheckBox "Desativar HTML nesta mensagem" que fica acima do botão Enviar
Espero que ajude |
|
| Voltar ao Topo |
|
 |
poolpay Novato

Registrado: Sábado, 17 de Junho de 2017 Mensagens: 7
|
Enviada: Ter Jun 20, 2017 7:09 am Assunto: Geração de Arquivo XML com componente XMLDocument |
|
|
Imex fiz como você disse ficou show só tem mais uma coisa tem como eu retirar os prefixos que ficou o fi: data tag <Descritor> e <fi:FundoInvestimento>
<fi:Codigo>2</fi:Codigo>
.
.
e das demais que esta dentro da <fi:FundoInvestimento>
veja abaixo pois no arquivo original não tem
<?xml version="1.0" encoding="ISO-8859-1"?>
<fi:FundosInvestimento xmlns="http://www.tce.sp.gov.br/audesp/xml/fundosinvestimento" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:gen="http://www.tce.sp.gov.br/audesp/xml/generico" xmlns:fi="http://www.tce.sp.gov.br/audesp/xml/fundosinvestimento" xsi:schemaLocation="http://www.tce.sp.gov.br/audesp/xml/fundosinvestimento ./fundosinvestimento/AUDESP_FUNDOS_INVESTIMENTO_2017_A.XSD">
<fi:Descritor>
<gen:AnoExercicio>2017</gen:AnoExercicio>
<gen:TipoDocumento>Fundos de Investimento</gen:TipoDocumento>
<gen:Entidade>4</gen:Entidade>
<gen:Municipio>7095</gen:Municipio>
<gen:DataCriacaoXML>2017-06-20</gen:DataCriacaoXML>
<gen:MesExercicio>6</gen:MesExercicio>
</fi:Descritor>
<fi:FundoInvestimento>
<fi:Codigo>2</fi:Codigo>
<fi:PercentualInvestido>100.00</fi:PercentualInvestido>
<fi:Resgate>200.00</fi:Resgate>
<fi:Reinvestimento>300.00</fi:Reinvestimento>
<fi:RendimentonoPeriodo>400.00</fi:RendimentonoPeriodo>
<fi:RendimentoTotal>500.00</fi:RendimentoTotal>
<fi:Saldo>600.00</fi:Saldo>
<fi:NumeroDocumentoAPR>APR</fi:NumeroDocumentoAPR>
<fi:ValueatRisk>700.0</fi:ValueatRisk>
<fi:Volatilidade>800.00</fi:Volatilidade>
<fi:FatoRelevante>FATO</fi:FatoRelevante>
<fi:Provisionamento>900.00</fi:Provisionamento>
<fi:QuantidadeCotas>100.000000</fi:QuantidadeCotas>
<fi:ValorUnitarioCota>100.000000000</fi:ValorUnitarioCota>
<fi:QuantidadeCotistas>1</fi:QuantidadeCotistas>
<fi:PatrimonioLiquido>100.00</fi:PatrimonioLiquido>
<fi:Observacao>OBS</fi:Observacao>
</fi:FundoInvestimento>
</fi:FundosInvestimento> |
|
| Voltar ao Topo |
|
 |
imex Moderador

Registrado: Sexta-Feira, 7 de Janeiro de 2011 Mensagens: 11666
|
Enviada: Ter Jun 20, 2017 3:21 pm Assunto: |
|
|
Experimente deixar a linha que adiciona esses nós da seguinte forma:
| Código: | with AddChild('Descritor', '') do
with AddChild('FundoInvestimento', '') do |
Espero que ajude |
|
| Voltar ao Topo |
|
 |
poolpay Novato

Registrado: Sábado, 17 de Junho de 2017 Mensagens: 7
|
Enviada: Ter Jun 20, 2017 6:21 pm Assunto: Geração de Arquivo XML com componente XMLDocument |
|
|
| Imex ja tinha tentado fazer isso, mas ele aparece no descritor e no FundoInvestimento o xmlns="" novamente |
|
| Voltar ao Topo |
|
 |
imex Moderador

Registrado: Sexta-Feira, 7 de Janeiro de 2011 Mensagens: 11666
|
Enviada: Ter Jun 20, 2017 9:13 pm Assunto: |
|
|
| Acho melhor você fazer uns testes com o XML gerado. Desconfio que tanto a versão com como a versão sem prefixo vão funcionar, inclusive porque os valores de xmlns e xmlns:fi definidos no início são iguais. |
|
| Voltar ao Topo |
|
 |
|