Huge XML file processing from IFS (IBMi)

Discussions relating to writing software in ILE RPG (RPG IV). This includes both fixed and free format RPG.
Post Reply
pshankmd
Posts: 11
Joined: Tue May 02, 2023 2:14 am

Huge XML file processing from IFS (IBMi)

Post by pshankmd »

Hi All,
Would like to get your thoughts on the situation below -

Need to process a huge XML (around 20MB size currently and could grow) from IFS folder using ILE RPG.

One option is to use RPG's built-in XML-INTO. Understand that there is a size limitation to use this function. Would this be a better option still?

Another option is to use the SQL capabilities. Came to know that it also has some limits. Not sure what are the limitations and how to get around these?

Any assistance on this would be appreciated.

Thanks!
Scott Klement
Site Admin
Posts: 658
Joined: Sun Jul 04, 2021 5:12 am

Re: Huge XML file processing from IFS (IBMi)

Post by Scott Klement »

I don't know what the SQL limits are (I prefer not to use SQL for this, I don't like how it works.)

For XML-INTO, you can use the %HANDLER BIF so that the entire XML document doesn't need to fit into a single data structure. That usually solves size limits...

If not, XML-SAX is more work to code, but allows you to work with more data and have a smaller memory footprint.

Finally, you could consider using Expat. Not many people have done that since XML-INTO and XML-SAX were added to the language, but if neither XML-INTO nor XML-SAX works for you, perhaps Expat would.
pshankmd
Posts: 11
Joined: Tue May 02, 2023 2:14 am

Re: Huge XML file processing from IFS (IBMi)

Post by pshankmd »

Thanks for your inputs Scott.
Will try XML-INTO with %HANDLER first. Are there any samples to refer for this?
Scott Klement
Site Admin
Posts: 658
Joined: Sun Jul 04, 2021 5:12 am

Re: Huge XML file processing from IFS (IBMi)

Post by Scott Klement »

I don't know -- I basically never use XML anymore (I used it a lot 15 years ago... but...) Please use Google to see if you can find examples.
pshankmd
Posts: 11
Joined: Tue May 02, 2023 2:14 am

Re: Huge XML file processing from IFS (IBMi)

Post by pshankmd »

Sure Scott, will check it, thanks!
pshankmd
Posts: 11
Joined: Tue May 02, 2023 2:14 am

Re: Huge XML file processing from IFS (IBMi)

Post by pshankmd »

Trying to use XML-INTO command to get data from XML file from IFS and got below error, due to usage of CDATA.

XML Element: <PriceListID><![CDATA[1]]></PriceListID>
DS subfield declaration: PriceListID varchar(10);

Error Message: The XML document does not match the RPG variable; reason code 5.
Reason code 5. The XML document contains extra XML attributes or elements that do not match subfields.

Kindly suggest how to parse <![CDATA[...]], to get value 1
Scott Klement
Site Admin
Posts: 658
Joined: Sun Jul 04, 2021 5:12 am

Re: Huge XML file processing from IFS (IBMi)

Post by Scott Klement »

I don't understand -- why would that CDATA cause the error you've listed? That doesn't make sense.
Scott Klement
Site Admin
Posts: 658
Joined: Sun Jul 04, 2021 5:12 am

Re: Huge XML file processing from IFS (IBMi)

Post by Scott Klement »

I tried it -- the CDATA works just fine.

Code: Select all

**free

dcl-c myXml '<test><PriceListID><![CDATA[1]]></PriceListID></test>';

dcl-ds test;
  PriceListId varchar(10);
end-ds;  

xml-into test %xml(myXml: 'case=convert path=test');
dsply PriceListId;

*inlr = *on;
The problem is somewhere else, but since you have only told us about the CDATA and nothing else, we cannot possibly tell you what's causing the actual problem.
pshankmd
Posts: 11
Joined: Tue May 02, 2023 2:14 am

Re: Huge XML file processing from IFS (IBMi)

Post by pshankmd »

Thank you Scott.
Looks like the issue was with DS declaration. Corrected it and now working fine with array of 29K elements.
Will change it to using %Handler and check it.
Post Reply