I received an XML-document via mail, i detached it and placed it into the IFS.
Then i wrote an RPG-program where i used the XML-INTO command to read the XML-document.
But, when i run my program i always get the error "The XML parser detected error code 302"
I think there's something wrong with the CCSID, the IFS-file is in CCSID 1252
Who can help me with this ?
Thx
Software/Hardware used:
ASKED:
January 29, 2008 8:30 AM
UPDATED:
February 19, 2008 3:22 PM
1) my XML-INTO statement
D XML_Source S 256a varying
D Inz(‘/home/ecn0010.xml’)
/free
XML-INTO ECN %XML(XML_source : ‘doc=file allowmissing=yes case=any’);
2) values
405C5C5C 5C5C5C5C 5C5C5C5C 5CC28587 89959589 ************Beginni
3C45434E 3E0D0A
3C73626C 5F45434E 3E0D0A
20203C45 434E3E45 43313639 20202020 203C2F45 EC169 BUNKOVSKY
20203C4C 6F63616C 43757374 6F6D6572 4E756D62 0010
20203C54 696D6553 74616D70 3E323030 382D3031 2008-01
Here is a RPG program that appears to work:
h dftactgrp(*no) dsbl_ECN ds qualified d dim(10) d ECN 50 d ECNName 50 d LocalCustomerNumber... d 50 d Company 50 dTimeStamp 50 dPSDS sds 429 qualified d XMLEntries 372 379i 0 dXMLFile s 20 inz('/xml3.txt') d varying dOptions s 50 inz('doc=file case=any - d path=ECN/sbl_ECN') /free xml-into sbl_ECN %xml(XMLFile :Options); dsply ('There were ' + %char(PSDS.XMLEntries) + ' entries found.'); *inlr = *on; return; /end-freeFor my testing I created an IFS stream file, CCSID tagged 1252, with the following:
Running the RPG program resulted in the first three elements of sbl_ECN being populated with the expected results, and the variable PSDS.XMLEntries set to a value of 3.
I hope this helps,
Bruce Vining
http://www.brucevining.com/
Your program helped me a lot, thanks
Still i got a CCSID issue with it
The problem is that the XML-document comes from our company in Russia and so, contains Russian Characters (for example <LocalCustomerNumber>Кл00481</LocalCustomerNumber> )
when i run my program i still get the parser error
This additional information certainly does help! Somewhere the system is being told that the data is in CCSID 1252. This is wrong. CCSID 1252 corresponds to Windows Latin 1, essentially Western European languages, and this CCSID does not contain the Cyrillic characters you are receiving. Now the question becomes what CCSID is being sent to you.
I suspect the data is in UTF8 (CCSID 1208) but cannot be sure. I do know that if it was in CCSID 1251 (Windows Cyrillic) that my sample program works without a CCSID error, but you also end up with the Cyrillic К being converted (incorrectly due to the CCSID mis-identification) to the Latin 1 Ê. As your previous pasting of the file in hex didn’t include the LocalCustomerNumber can you paste that particular entry in its entirety? That will help determine what CCSID is in use. Or better, ask whoever is sending you the document what it is
But the good news is we know it’s not a problem with XML-INTO!
The big question now though is what you want to do with these Cyrillic values. If you need to store them (and characters from other languages) in your databases then you have some design issues to work through — issues that are larger than I would feel comfortable trying to tackle in this forum.
Bruce Vining
http://www.brucevining.com/
As an update, Guygeb sent me offline a LocalCustomerNumber entry. The value was:
where the initial 4 bytes (x’D09AD0BB’) are the Cyrillic characters ‘Кл’ encoded with UTF8. With this entry I was easily able to recreate the 302 failure
To correct the situation I:
1. Used the Change Attribute command CHGATR to change the *CCSID value of the stream file to 1208 (the CCSID for UTF8).
2. Changed the RPG program above to define LocalCustomerNumber as a UCS2 field:
With these changes the program then correctly processed the XML file. The RPG LocalCustomerNumber variable was set to x’041A043B’ in the intial four bytes of the field. x’041A043B’ is the UCS2 value for the Cyrillic character string ‘Кл’.
Bruce Vining
http://www.brucevining.com/
Hey,
i tested your latest remarks and it works just fine (of course)
in my program there’s a dim(32767) to tell RPG how many records (customers) are expected
what if there are more dan 32767 customers ?
Dsbl_ECN DS qualified
D dim(32767)
D ECN 5a
D ECNName 25a
If you anticipate that there may be more entries than will fit into an array then you should consider using the %HANDLER option of XML-INTO. This way XML-INTO would call your function each time the array becomes full and once, at the end, for a partical array.
Bruce Vining
http://www.brucevining.com/