Solved

How to create XML correctly?

Posted on 2013-01-18
4
418 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:Delphiwizard
  • 2
4 Comments
 
LVL 36

Expert Comment

by:Geert Gruwez
ID: 38792676
0
 

Author Comment

by:Delphiwizard
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 500 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:Delphiwizard
ID: 38793757
That does do the trick. Thank you very much for your help.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now