Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to create XML correctly?

Posted on 2013-01-18
4
Medium Priority
?
431 Views
Last Modified: 2013-01-18
Hi,

I need to create following XML content:
		<SalesInvoiceList>
			<SalesInvoice ReferenceNumber="2006033">
				<ReferenceNumber>2006033</ReferenceNumber>
				<ContactPersonReference xsi:nil="true" />
				<CustomerReference ID="15" />
				<RecipientAddress>
					<Name>Zwembad Varik</Name>

Open in new window

I've come up with following code, but that doesn't have the correct result:
  // declared a private variables:
  Level0, Level1, Level2, Level3, Level4, Level5, Level6, Level7, Level8 : IXMLNode;

  Level3 := Level2.AddChild('SalesInvoice');
  Level3.Attributes['ReferenceNumber']                := QFacturenRlz.FieldByName('ReferenceNumber').AsString;
    Level4 := Level3.AddChild('ReferenceNumber');
    Level4.Text                                       := QFacturenRlz.FieldByName('ReferenceNumber').AsString;
    Level4.AddChild('ContactPersonReference');
    Level4.Attributes['xsi:nil']                      := 'true';
    Level4.AddChild('CustomerReference');
    Level4.Attributes['ID']                           := QFacturenRlz.FieldByName('ID').AsString;
    Level4.AddChild('RecipientAddress');
      Level5 := Level4.AddChild('Name');
      Level5.Text                                     := QFacturenRlz.FieldByName('FullName').AsString;

Open in new window

How can this be done correctly?
0
Comment
Question by:Stef Merlijn
  • 2
4 Comments
 

Author Comment

by:Stef Merlijn
ID: 38792917
I've read the examples, but it never goes to a level where it shows how to solve my question.
My code creates the following:
<SalesInvoiceList>
    <SalesInvoice ReferenceNumber="2">
        <ReferenceNumber ID="8884" xsi:nil="true">
        2
        <ContactPersonReference/>
        <CustomerReference/>
        <RecipientAddress/>
              <Name>
              Companyname

Open in new window


So it mixes up assigned values to nodes.
0
 
LVL 19

Accepted Solution

by:
Thommy earned 2000 total points
ID: 38793616
It should go somehow like that...

uses XMLIntf,XMLDoc;

...

procedure TForm1.Button1Click(Sender: TObject);
 var
   Doc: IXMLDocument;
   Level1, Level2,Level3: IXMLNode;
begin
  Doc := NewXMLDocument;
  Level1 := Doc.AddChild('SalesInvoiceList');

  Level2 := Level1.AddChild('SalesInvoice');
  Level2.Attributes['ReferenceNumber']:='2006033';

  Level2.AddChild('ReferenceNumber');
  Level2.ChildValues['ReferenceNumber']:='2006033';

  Level3:=Level2.AddChild('ContactPersonReference');
  Level3.Attributes['xsi:nil']:='true';

  Level3:=Level2.AddChild('CustomerReference');
  Level3.Attributes['ID']:='15';

  Level3:=Level2.AddChild('RecipientAddress');
  Level3.AddChild('Name');
  Level3.ChildValues['Name']:='Zwembad Varik';

  Doc.SaveToFile('c:\temp\test.xml');
end;

Open in new window

0
 

Author Closing Comment

by:Stef Merlijn
ID: 38793757
That does do the trick. Thank you very much for your help.
0

Featured Post

[Webinar] Cloud Security

In this webinar you will learn:

-Why existing firewall and DMZ architectures are not suited for securing cloud applications
-How to make your enterprise “Cloud Ready”, and fix your aging DMZ architecture
-How to transform your enterprise and become a Cloud Enabler

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Loops Section Overview
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question