Jump to content
msd

XML: Parsing UBL 2.1 in Delphi

Recommended Posts

Hello

 

I have one XML situation, but I'm new in this world (parsing complex XML in Delphi).

The XML file is a UBL 2.1 model invoice, and it has more nodes with child nodes, and child nodes have new child nodes, and so on.

Do I need to make an infinite loop of reading and inspect every node for chield?

My intention is to not lock structure; there are nodes that are not mandatory, so I just want to parse XML and use that data that is in the converted XML file.

 

I'll attach sample XML to this message.

 

Thanks to all of you in advance for any help...

sample_invoice.xml

Share this post


Link to post

I know for XML mapper, but, as I told you before, there is no full XML every time; one time XML has all UBL 2.1 nodes, one time only nessersty nodes.

 

Does XML Mapper recognize this situation?

Share this post


Link to post
Posted (edited)

Using native XML Data Binding in Delphi. 

uses Sample_Invoice;

{$R *.dfm}

procedure TForm1.BitBtn1Click(Sender: TObject);
var Invoice: IXMLInvoiceType;
begin
  Invoice:=LoadInvoice('sample_invoice.xml');
  Showmessage(Invoice.AccountingSupplierParty.Party.PartyName.Name);
  Showmessage(Invoice.AccountingCustomerParty.Party.PartyName.Name);
  Showmessage(Invoice.InvoiceLine.Item.Name);
end;

end.

Just did a small test and works great..

Edited by Die Holländer

Share this post


Link to post

Do you have an XML Schema file (typically file extention = .xsd) for the UBL 2.1 model invoice?

If so you can use this with XML Mapper to generate a transform (at design time) which you then use in code

so that it can populate a client dataset (at run time) with data from an incoming XML file. 

With this approach XML files that only contain partial amounts of data (as you anticipate)

are handled correctly.

  • Like 1

Share this post


Link to post

The problem will be that there are many different versions of this format. There is no one correct scheme. And I think he will receive more of these invoices in the future

  • Like 1

Share this post


Link to post

It is much clear now how Delphi works with complex XML files...

 

Thanks to all of you :-)

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×