WD26 Create XML file
April 04, 2022 02:24PM
Hey everybody

I regularly create an xml file of many records (> 30000)
I notice that the larger the file gets, the longer it takes for records to be written.
Here is a small example of how I do it now.

MaxTeller = HNbRec(TblArticles)
Teller = 0
FOR EACH TblArticles
       Teller ++	
	ProgressBar(Teller,MaxTeller, "Prepare items for checkout [%Teller%]/[%MaxTeller%]")
	INT_FillXmlData()
END
XMLSave(ArticleXML file,NameXML file,XMLFormatting)


INTERNAL PROCEDURE INT_VulXmlData()
	ArtikelXMLbestand.job.command.data.plu[Teller].code										= TblArtikelen.TblArtikelnr
	ArtikelXMLbestand.job.command.data.plu[Teller].name										= NoSpace(TblArtikelen.Omschrijving1)
	ArtikelXMLbestand.job.command.data.plu[Teller].text2									= NoSpace(TblArtikelen.Omschrijving2)
	ArtikelXMLbestand.job.command.data.plu[Teller].department								= TblArtikelen.TblSubgroepnr
	ArtikelXMLbestand.job.command.data.plu[Teller].isopen									= TblArtikelen.PrijsAanpasbaar =  1 ? "true" ELSE "false"
	ArtikelXMLbestand.job.command.data.plu[Teller].isactive									= TblArtikelen.Inactief 		= 0 ? "true" ELSE "false"
	ArtikelXMLbestand.job.command.data.plu[Teller].isnegative								= TblArtikelen.Isnegatief		= 1 ? "true" ELSE "false"
	ArtikelXMLbestand.job.command.data.plu[Teller].isscaleproduct							= TblArtikelen.GewichtArtikel	= 1 ? "true" ELSE "false"
	ArtikelXMLbestand.job.command.data.plu[Teller].tare_mode								= "Fixedtare"
	ArtikelXMLbestand.job.command.data.plu[Teller].shelflife								= TblArtikelen.THT
	ArtikelXMLbestand.job.command.data.plu[Teller].IsDeposit	

END



But this is getting slower and slower after about 15000 records

Can I solve this?



Edited 1 time(s). Last edit at 04/04/2022 02:26PM by jtadebruin.
Argus
Re: WD26 Create XML file
April 04, 2022 10:40PM
My understanding is that each time you use the XMLxxxx functions to add in your string, the xml tree is read to position your data at the right place, and that is what is slowing you down...

Now, as an xml is simply text, you can create your xml WITHOUT any xml function... To do that, you need:
- 1 string with the "structure" of your file and a %1 where you data content will be inserted
- 1 string with the "structure" of each "record" with %1, %2,%3 where each data item will be inserted
- 1 empty work string
then you can loop on your data, each time build a "record" with string 2 above (and the buildstring function) then ADD that "record" into the work string

Once you are out of the loop, just build your xml file with a stringbuild of the 1rst string above and the work string

This process will NOT slow down as long as you don't use all your pc's memory and it should be significantly faster than using the xml functions
Re: WD26 Create XML file
April 05, 2022 06:43PM
Yep i understand and will try this

Thanks
Re: WD26 Create XML file
April 17, 2022 06:43PM
Hey Argus,

Yep a great tip.!!
It works many times faster

Thank you very much


Jan
Re: WD26 Create XML file
April 19, 2022 11:33AM
hi guys, could you post a small example?
thanks!!
Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: