msd 5 Posted August 29 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
Roger Cigol 103 Posted August 29 Are you aware of the XML mapper tool? 1 Share this post Link to post
msd 5 Posted August 29 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
sh17 26 Posted August 29 This is a ZUGFeRD-UBL-Invoice My Repo LandrixSoftware/XRechnung-for-Delphi: XRechnung Implementation for Delphi (github.com) reads currently XRechnung in UBL and CII Format If you can wait a little longer, UBL support for all other ZUGFeRD formats will be available in September LandrixSoftware/ZUGFeRD-for-Delphi: ZUGFeRD / Factur-X Implementation for Delphi (github.com) 1 Share this post Link to post
Die Holländer 45 Posted August 29 (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 August 29 by Die Holländer Share this post Link to post
Roger Cigol 103 Posted August 29 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. 1 Share this post Link to post
sh17 26 Posted August 29 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 1 Share this post Link to post
msd 5 Posted August 30 It is much clear now how Delphi works with complex XML files... Thanks to all of you :-) Share this post Link to post
Attila Kovacs 629 Posted August 31 I'm curious how long it will take before we have to rewrite all the E-crap in JSON. 1 Share this post Link to post
Attila Kovacs 629 Posted August 31 (edited) Btw. I used this app for the validation: https://www.xml-buddy.com/ You can batch-validate the xml's you generate against the schematrons with a console app. Edited August 31 by Attila Kovacs 1 Share this post Link to post