XML-SAX strange issue

Any IBM i topic that does not fit in another forum
Post Reply
JustBrowsing
Posts: 3
Joined: Thu Aug 04, 2022 2:39 pm

XML-SAX strange issue

Post by JustBrowsing »

Hi Everyone, first post for me and it's a bit of a weird one but probably simple? Current task is to consume XML file from external source and we opted for XML-SAX as the document has a lot of extraneous data we don't necessarily need. The issue occurs when we try to pass the file path (full file path and file name) to the program as a parameter in the %xml() section. When we do this we get XML Parsing failed with message CPE3025 which essentially says no such path or directory. We have the filename field defined as varying length 256A and we use %trim() to peel off any blanks. We know the file is okay because fi we hard code the filename in the %xml() everything works as desired. I've included some snippet of the code below with the two %xml() one which does and one which does not work. I should add that we are on V7R4 of the OS.



* Entry Point Prototype - These are the required Parms
D P3P300X PR
D XmlFileName 256a

...
D IgnoreIt s 1a inz
D XMLfile s 256a inz varying
....

// desperate measures
XMLfile = XmlFileName;
XMLFile = %trim(XMLFile);

xml-sax %handler(XmlHandler: IgnoreIt)
%xml(XMLfile : 'doc=file'); <--- This does not work
%xml('/Home/Xml/ActualFile.XML' : 'doc=file'); <--- This does work
jonboy49
Posts: 77
Joined: Wed Jul 28, 2021 8:18 pm

Re: XML-SAX strange issue

Post by jonboy49 »

Well you don't show us the original content of the file name parm so we can't even be sure that it was the same.

If this works (re-done in free-form 'cos I can't be bothered to work out the spacing):

Code: Select all

Dcl-s  XMLfile varchar(256) inz('/Home/Xml/ActualFile.XML');
xml-sax %handler(XmlHandler: IgnoreIt) %xml(XMLfile : 'doc=file'); 
then the problem lies in the parameter you are passing in. By the way ... why not make that a varchar to begin with?
Scott Klement
Site Admin
Posts: 257
Joined: Sun Jul 04, 2021 5:12 am

Re: XML-SAX strange issue

Post by Scott Klement »

You appear to have a 256A input parameter. How are you calling that? Have you made sure that the caller is providing the full, correct, 256A?

If you are using the CALL command from the command-line, please be advised that it typically sets character parameters to 32A -- so this would not work well unless steps are taken to force it to expand the parameter to 256, or a *CMD interface is provided that sets the length to 256.
JustBrowsing
Posts: 3
Joined: Thu Aug 04, 2022 2:39 pm

Re: XML-SAX strange issue

Post by JustBrowsing »

Thanks for the reply.

It's been about 8 years since I wrote RPGLE code and that was on a V5R4 box, so not as familiar with complete free format although i must say that I love what I see with it.

Your test proved fruitful, when I coded the filename in the inz of the variable declaration it worked. So whatever I am passing in is the issue.

I'm just calling the program from command line for testing.

Type command, press Enter.
===> call p3p300x ('/Lakeside/IN/SC_Sample.XML')

Scott, your comment just banged me on the head... this would normally be something called from another routine in most likely in batch.
jonboy49
Posts: 77
Joined: Wed Jul 28, 2021 8:18 pm

Re: XML-SAX strange issue

Post by jonboy49 »

"I'm just calling the program from command line for testing"
And there is your problem right there.

Your code is expecting a 256 char variable but what it is getting is a 32 byte character variable - which is the default from the command line. The system will have padded with blanks up to that point but after that you'll get whatever gibberish is lying around in memory. If you had looked at the variable in debug you'd have probably seen it. Because of the gibberish your trim was ineffective.

To test from the command line either make sure that your parm is 32 chars or greater in length or use a command to call the test program.
JustBrowsing
Posts: 3
Joined: Thu Aug 04, 2022 2:39 pm

Re: XML-SAX strange issue

Post by JustBrowsing »

Many thanks to you, this was the issue.

If I'm going to be coding in RPGLE again (although I would think minimally) perhaps it's a good time to explore complete free format.

Cheers!
jonboy49
Posts: 77
Joined: Wed Jul 28, 2021 8:18 pm

Re: XML-SAX strange issue

Post by jonboy49 »

You're welcome and if you are indeed in learning mode:

https://authory.com/JonParisAndSusanGan ... e-Form-RPG

That may help.

I was going to call the series the "Old Farts Guide ..." but they wouldn't;t let me <grin>
Post Reply