Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delphi generated XML files 1

Status
Not open for further replies.

StuM

MIS
Jan 16, 2001
148
US
I'm new to Delphi and XML .... lucky me ...
I need to produce XML files to send data files I have in paradox files. Where do I start looking for the "right" tools to use in Delphi to write this ?
 
What version of Delphi do you have?

Clive
Runner_1Revised.gif

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer." (Paul Ehrlich)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096
 
Version 7 I downloaded OpenXML and XMLPartner. I am trying to learn to create an XML file .... slow process .. I'm having problems with multi-nodes.

 
When I asked what version you were using, I really meant what edition are you using because Enterprise & Architect editions of Delphi have built-in XML components whereas the Professional edition doesn't. I take it that you don't have an Enterprise/Architect edition of Delphi 7?

If you're very new to XML it's worth learning a bit about it first. W3Schools is always very good for making a start on a web technology: (see XML Tutorials in the left-hand navigation pane).

I've been reading a book called XML for the World Wide Web by Elizabeth Castro, which has been really helpful in picking up XML too.

If you're going to be doing a lot of work with XML it would be very useful to familiarise yourself with Altova's XMLSpy (there's a free trial of the Home Edition available which you can use as an evaluation copy) - it's one of the best XML Editors out there and I've found it to be very useful indeed.

If you give details of the problem you are having with multi-nodes we may be able to help you.

Clive
Runner_1Revised.gif

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer." (Paul Ehrlich)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096
 
Stretchwickerster: THANKS
I have enterprise edition..
I found the w3schools.com and have been working thru....
I'll look inside delphi .... but I learn better from examples WITH the book.

Problems:

I try to generate this
<scheduledata version="0.6">
<aircraft regnr="N100HG">
<updateenddate>
<datetime>2006-05-08T20:16:19Z</datetime>
<schedule>
<activity>
<type>Ferry</type>
<start>
<airport>SUS</airport>
<datetime>2006-04-24T12:00:00Z</datetime>
</start>
<end>
<airport>SUS</airport>
<datetime>2006-05-02T05:00:00Z</datetime>
</end>
<allowlisting>yes</allowlisting>
</activity>
</Schedule>
</updateenddate>
</aircraft>



* * * * * BUT I get this * * * * *
<scheduledata version="0.6"/>
<aircraft regnr="N100HG">
<updateenddate/>
<datetime>2006-05-08T20:16:19Z</datetime>
<schedule/>
<activity/>
<type>Ferry</type>
<start/>
<airport>SUS</airport>
<datetime>2006-04-24T12:00:00Z</datetime>
<end/>
<airport>SUS</airport>
<datetime>2006-05-02T05:00:00Z</datetime>
<allowlisting>yes</allowlisting>
</aircraft>

 
What delphi code are you using to generate this XML?

Clive
Runner_1Revised.gif

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer." (Paul Ehrlich)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096
 
Here's the code .... It might not match exactly... since I having been trying different things.

* * * * * * * * * * *
procedure TForm1.Button1Click(Sender: TObject);
Var
aElem,aElem1,aElem2,PElem,QElem,QElem1,QElem2,QElem3,RElem: TXpElement;
API: TXpProcessingInstruction;
FLD,FLD1: String;
// XML1:TxpObjModel; On form
DTCurr,DT1 : TdateTime ;
FltType,DTime,DDate : String ;

begin

DTCurr:= now;
DDATE:= AVTIME(DTCurr);
Showmessage('DATE= '+DDATE);

XML1:=TXpObjModel.create(nil);

FLD:='scheduledata';
FLD1:='0.6';
AElem:=XML1.Document.CreateElement(FLD);
XML1.Document.appendChild(AElem);
AElem.SetAttribute('version',FLD1);


while not tableinput.eof do
begin
FLD:='aircraft';
FLD1:= 'N'+tableinput.Fields[0].asstring;
AElem:=XML1.Document.CreateElement(FLD);
XML1.Document.appendChild(AElem);

AElem.SetAttribute('regnr',FLD1);
memo1.Text:= memo1.Text + (FLD1)+' '#13#10;



FLD:='updateenddate';
AElem2:=aElem.CreateChildElement(FLD);
AElem2.CreateChildText(DDATE);

FLD:='datetime';
AElem2:=aElem.CreateChildElement(FLD);
AElem2.CreateChildText(DDATE);

FLD:='schedule';
FLD1:='';
AElem1:=aElem.CreateChildElement(FLD);
AElem1.CreateChildText(FLD1);

FLD:='activity';
FLD1:='';
AElem1:=aElem.CreateChildElement(FLD);
AElem1.CreateChildText(FLD1);

FLD:='type';
QElem:=aElem.CreateChildElement(FLD);


If tableinput.Fields[8].AsString='A'then FLTtype:='Ground'
Else FLTtype:= 'Ferry';

Qelem.CreateChildText(FLTtype);

FLD:='start';
FLD1:='';
QElem2:=aElem.CreateChildElement(FLD);
QElem2.createChildText(FLD1);

FLD:='airport';
FLD1:= tableinput.Fields[9].asstring;
QElem1:=aElem.CreateChildElement(FLD);
QElem1.createChildText(FLD1);

FLD:='datetime';
DTIME:=AVTIME(tableinput.Fields[3].AsDateTime);
QElem1:=aElem.CreateChildElement(FLD);
QElem1.createChildText(DTIME);


FLD:='end';
FLD1:='';
QElem3:=aElem.CreateChildElement(FLD);
QElem3.createChildText(FLD1);

FLD:='airport';
FLD1:= tableinput.Fields[9].asstring;
QElem3:=aElem.CreateChildElement(FLD);
QElem3.createChildText(FLD1);

FLD:='datetime';
DTIME:=AVTIME(tableinput.Fields[6].AsDateTime);
QElem3:=aElem.CreateChildElement(FLD);
QElem3.createChildText(DTIME);


QElem:=aElem.CreateChildElement('allowlisting');
QElem.createChildText('yes');

tableinput.Next;
end ; // while not EOF

XML1.FormattedOutput:= true;
XML1.SaveToFile('c:\XMLTEST1.XML');
XML1.Destroy;

showmessage('function done');


end;

* * * * * * * * * * * *

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top