Solved

How to create XML correctly?

Posted on 2013-01-18
4
425 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 37

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
DBGrid or StringGrid ? 6 120
RESTRequest Parameter 4 54
Microsoft Access 97 and Delphi XE2 9 72
Firemonkey BASS_Init into a thread 17 55
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

749 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