How to define an empty XML tag with Delphi?

Asked

Viewed 305 times

1

I developed a system, still at Delphi 6, for Occupational Medicine, I know I have to update, but it’s impossible to do this now.

My problem is with creating an XML file to export data to E-social.

I am using the following routine to create an empty tag:

exame := Aso; 
exame.AddChild('exame'); 
Aso.ChildNodes['exame'].NodeValue := ''; 

only that the result is: </exame> and I need it to be: <exame></exame> or is opened and closed.

  • And what’s the matter with you?

  • Junior, thank you very much. The problem is that I can not create an empty tag or without the blank, type <exam></exam>, using the routine in my question.

  • Well my friend, what is the problem that this causes you? As far as I understand, there is no problem in this. </name> is = a <name></name>

  • Junior thanks again. The problem is that when sending me returns error in the exam item. Because in the xml that is generated this <scan/>. My friend how do I get out of this ?

  • Junior in reality what happens is that when validating the generated file does not pass the error here </exam> when there are no complementary tests. So how to pass the validation ? Thank you very much.

1 answer

1

Suggestion for immediate troubleshooting is not to use the Delphi component to generate xml.

And your problem is not only the version of Delphi, here we use the latest version and the same problem occurs.

In this case, it may be that on the other side you are not validating as XML, but as a plain text, looking for specific tags, opening and closing.

Therefore.

var
  vArquivo: TStringList;
begin
  vArquivo := TStringList.Create;
  vArquivo.Add('<?xml version="1.0" encoding="8859-1" ?>');
  vArquivo.Add('<XML>');
  ... outras tags
  vArquivo.Add('<exame>' + VariavelComValor + '</exame>');
  vArquivo.Add('</XML>');
  vArquivo.SaveToFile('Unidade:Caminho\NomeArquivo.xml');
end;
  • Junior thanks for the guidance. I really hadn’t thought about using a Stringlist, I’m using Xmldocument. I will redo the routine and return to you whether it worked or not. Curious is that I was able to validate when there are complementary exams.

  • Junior unfortunately did not work. This way he does not generate an xml file but a common txt. Has another alternative ?

  • Negative my friend, xml is a plain text file. I even use this procedure to communicate with a Soap api.

  • Okay, got it. I’m just not into it, so my difficulty. Well my doubt is that I tried to open in internet explorer and appeared the embranco page. Using the other way it appeared normally. Another thing, how to endeavor the document ? Thank you very much for your attention in helping me.

  • "in internet explorer and appeared the embranco page" then you saved with structure failure. Here, opens in any browser. Even valid in any online validator.

  • OK. I am finishing the new routine. I can send it to you for your evaluation ?

  • If possible edit your question, add as detail.

  • Friend, I used Notepad++ and the file opened nice, I was just not endeared.

  • I did everything right, it generated beauty but when validating the xmlpaserdoc error. I am using the program of Acbr, it may have something to do ?

Show 4 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.