XML-INTO XML parser detected error code 2.

Discussions relating to writing software in ILE RPG (RPG IV). This includes both fixed and free format RPG.
Scott Klement
Site Admin
Posts: 635
Joined: Sun Jul 04, 2021 5:12 am

Re: XML-INTO XML parser detected error code 2.

Post by Scott Klement »

When you post code, please put [code] before the first line of the snippet, and [/code] after it. This time around you posted a lot of code with very few explanations, and it is very hard to read. Sorry, I don't have time right now to go through and reformat the messages for you, like I did earlier.

From the little bits of text I saw, it seems like you need to code countprefix for your array. Please look into the countprefix option and see if it solves the problem.

Tip: When you have a problem like this, post a complete, but very simple, program that reproduces the problem. This saves us a lot of time trying to help you, and makes it more likely that we're willing to invest the time to help you.
onie
Posts: 11
Joined: Mon Nov 07, 2022 8:27 pm
Location: Florida

Re: XML-INTO XML parser detected error code 2.

Post by onie »

Thank you, I will remember to place [code] and [/code] next time around the code. Still learning the rule on posting to the site. I did try to use the count prefix and still had the "Parsing error code 2". I also changed the %XML options to case=convert and removed the allowextra=yes and allowmissing=yes and the trim=all. The name space was removed as I sub-string the parsing sting to start with the <result> tab to the end of the xml data.

The xml is a file received to the IFS after an HTTP request for the card information. When I view the IFS file it is one long string of data, displayed in a block of several lines. I copied this to note pad so I could break it down to the tag groups. All the data structures load until the array data structure that is set to an array of 10 and the data sent is only two elements and they load. Then the program blows with the parsing error.

I use the '_C_IFS_fopen' as read only and '_C_IFS_fgets' to read the data and of course the '_C_IFS_fclose' to close the file.

Code: Select all

 
FilePTR = OpenFile(%addr(PathFile):addr(OpenMode)'

Dow (ReadFile(%addr(RtvData):32767:FilePtr) <> *null);
   RtvDate = %xlate(x'00' : ' ' :RtvDate); //End of record null
   RtvDate = %xlate(x'25' : ' ' :RtvDate); //Line feed (LF)
   RtvDate = %xlate(x'0D' : ' ' :RtvDate); //Cariage return (CR)
This is different than the old unix command, that should not be an issue ,Right?
When I am in debug, I see the 2 elements do load to the array and then the error happens.

Thank you for all your advice. Onie
Scott Klement
Site Admin
Posts: 635
Joined: Sun Jul 04, 2021 5:12 am

Re: XML-INTO XML parser detected error code 2.

Post by Scott Klement »

Sorry, I don't understand why you are searching for <Result> and substringing off all of the XML before it. Use the "path" option on xml-into so that this isn't necessary -- see the example I posted earlier. I already showed you how to make the whole thing work.

I don't understand what you mean by "This is different than the old unix command". What unix command are you referring to?
onie
Posts: 11
Joined: Mon Nov 07, 2022 8:27 pm
Location: Florida

Re: XML-INTO XML parser detected error code 2.

Post by onie »

{code}

Dcl-PR OpenFile INT() EXTPROC('open');
*N POINTER VALUE OPTIONS(*STRING);
*N INT(10) VALUE;
*NUNS(10) VALUE;
*N UNS(10) VALUE OPTIONS(*NOPASS);
*N UNS(10) VALUE OPTIONS(*NOPASS);
*N UNS(10) VALUES OPTIONS(*NOPASS);
END-PR;

DCL-PR READFILE INT(10) EXTPROC('read'_);
*N INT(10) VALUE;
*N POINTER VALUE;
*N UNS(10) VALUE;
END-PR

DCL-PR CLOSEFILE INT(10) EXTPROC('close');
*N UNS(10) VALUE;
END-PR;
{/CODE}

I was told that these above were the old APIs and they referred to them as Unix style. The new 'C' API's '_C_IFS_fopen' ,
'_C_IFS_fget' and '_C_IFS_fclose' , were supposed to be easier to work with since the end of record, line feed and carriage return
are replaced with blanks. I am new to working with XML data and I was not sure if these blanks could have caused any issues with the xml-into and the array data. I do have it working with the read of the file without stripping off the front of the xml and start the parsing at the <result> tag. I don't understand why the parser would give an error when parsing the string and the file works just fine. The only thing I could relate it to is it needed matching tags from the part of the file that was stripped off. Similar to and IF statement with no ENDIF.
Thank you for the help. Onie
Scott Klement
Site Admin
Posts: 635
Joined: Sun Jul 04, 2021 5:12 am

Re: XML-INTO XML parser detected error code 2.

Post by Scott Klement »

open(), read(), write(), close() are UNIX APIs.
fopen(), fgets(), fputs(), fread(), fwrite(), fclose(), etc are ANSI C APIs.

Not sure which one is newer -- both date back to at least the 1970's.

I don't understand why you need to use any of these.... just let XML-INTO read the file.
onie
Posts: 11
Joined: Mon Nov 07, 2022 8:27 pm
Location: Florida

Re: XML-INTO XML parser detected error code 2.

Post by onie »

My code calls a server that sends the XML file to the IFS and if the process is successful, I then open and read the file and parse the data to data structures and next I will write the data to a file.

I have done this program in steps as I have never done any of this before. Once I got the server to return the file, next I read the file from the IFS and then parse it with the xml-into %xml to a data structure and next will load the data to a file. This has been a test process to learn how to do all of these steps.

Thank you. Onie
Scott Klement
Site Admin
Posts: 635
Joined: Sun Jul 04, 2021 5:12 am

Re: XML-INTO XML parser detected error code 2.

Post by Scott Klement »

but... XML-INTO can read the file from the IFS for you, you dont' need to read it manually.

Go back to the example I posted earlier and see how it works. viewtopic.php?p=994#p994
onie
Posts: 11
Joined: Mon Nov 07, 2022 8:27 pm
Location: Florida

Re: XML-INTO XML parser detected error code 2.

Post by onie »

Thanks, Scott, for your patients.
The file is dumped into the IFS with a long path: '/xxx/webservices/log/20221206050906133925_623117_xxxxx_getCard.XML ' that is stored in a variable
FilePath. LOL.... and this of course did not work : ' path=filepath/soapenv:Envelope/soapenv:Body/ns5:getCardResponse/result/cardNumber' with %XML.
The current data and time are part of the path where the IFS file is located, so doing the open and read of the file worked with the using
of the xml path. I couldn't figure out how to get %XML to accept this file path to the actual XML data.

{code}
Filepath = IFSPATH + '/' +
%EditC(%Dec(%TimeStamp):'X') + '_' +
%EditC(JobNum:'X') + '_' +
%Trim(UsrNme) + '_' + (xxxxx in my example)
'getCard.XML';
{/code}
Scott Klement
Site Admin
Posts: 635
Joined: Sun Jul 04, 2021 5:12 am

Re: XML-INTO XML parser detected error code 2.

Post by Scott Klement »

Please use [code] and [/code] around your code. You have been providing {code} and {/code} instead, and as you can see if you read your messages after you post them, this doesn't work.

The path= option in the 2nd parameter to %XML is not for the file path. It is just the path of elements to extract within your XML document.

To use a file path, you put it in the XmlData variable (instead of the document itself) and code "doc=file" in the 2nd parameter. Again, see my earlier example. In that example, the file path was 'onie.xml' and the element path was 'Envelope/Body/getCardResponse/result/limits'. These are two different things supplied in two different places.
onie
Posts: 11
Joined: Mon Nov 07, 2022 8:27 pm
Location: Florida

Re: XML-INTO XML parser detected error code 2.

Post by onie »

Thank You very much for all your help.
All working very fine now.
Onie
Post Reply