Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to create XML correctly?

Posted on 2013-01-18
4
Medium Priority
?
430 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
 

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

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

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…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

721 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