|
Hello everyone! I need help with XML Interface for RPG (Qxml4PR310). My programm creates an XML tree using DOMparser, collects data from DB2 file and puts them in appropriate nodes and in the end writtes created XML tree in streamFile (on IFS) using QxmlWriteOutputStream procedure. It's not more complicated then IBM's examles in eSeries Informaton Center. Only problem is created XML stream file which should be readable on windows platform whith desired code page (in my case windows-1250). I red all literature to figure out how to use different CCSIDs with mentioned API but still I have no clue how to write stmf with CCSID 1250. Data in DB2 file is with CCSID 870 and systems default CCSID is 870. I'll describe what I'm doing in code, so maybe somebody find mistake: /COPY QSYSINC/QRPGLESRC,QXML4PR310 DDomDoc@ S * DDomNode@ S * DDomImpl@ S * DRootElem@ S * DParentElem@ S * DChildElem@ S * DProdElem@ S * DDataVal@ S * Dstrgbuf@ S * DpomString S 256A inz(*blanks) *a lot of code goes here ****creation of an element that will contain child element *---create 0terminated string for value Sudionik--------- C EVAL %str(strgbuf@:256)='Sudionik' *---get adress of newly created DOMstring from 0terminated *---string coded with CCSID 870 C EVAL DomString1@= C QxmlDOMString_new(strgbuf@: C 870: C 8) *---create new element in DOM document with name stored at adress DOMString1@ *---Qxml_INDOMSTR constant (-1) idicates that DOMString1@ pointing *---at DOMString object C EVAL ParentElem@=QxmlDOM_Document_createElement C (DomDoc@: C DOMString1@: C Qxml_INDOMSTR: C 0) C*---add parent element on addres ParentElem@ to root element list C EVAL child@ = QxmlDOM_Node_appendChild C (RootElem@: C ParentElem@) *---clear resources that are not in use any more C CALLP QxmlDOM_Node_delete(child@) C CALLP QxmlDOMString_delete(DOMString1@) ****creation of an child element 4 previosly created parent element *---create 0terminated string for value VBDI--------- C EVAL %str(strgbuf@:256)='VBDI' *---get adress of newly created DOMstring from 0terminated *---string coded with CCSID 870 C EVAL DomString1@= C QxmlDOMString_new(strgbuf@: C 870: C 4) *---create new element in DOM document with name stored at adress DOMString1@ *---Qxml_INDOMSTR constant (-1) idicates that DOMString1@ pointing *---at DOMString object C EVAL ChildElem@=QxmlDOM_Document_createElement C (DomDoc@: C DOMString1@: C Qxml_INDOMSTR: C 0) *---add child element to Parent Element C EVAL child@ = QxmlDOM_Node_appendChild C (ParentElem@: C ChildElem@) *---clear resources that are not in use any more C CALLP QxmlDOM_Node_delete(child@) C CALLP QxmlDOMString_delete(DOMString1@) ***Creation of TXT node that will contain value *---VBDI is file field (numeric), move it to character field and convert *---character field pomString to null-terminated string C movel VBDI pomString C EVAL %str(strgbuf@:256)=%trim(pomString) *---create TXT node and set its value from null-terminated string on strgbuf@ *---address. C EVAL DataVal@ = C QxmlDOM_Document_createTextNode C (DomDoc@: C strgbuf@: C 870: C 4) *---ADD txt node pointed by DataValue@ to child element C EVAL child@ = QxmlDOM_Node_appendChild( C ChildElem@: C ProdDataVal@) *---clear resources that are not in use any more C CALLP QxmlDOM_Text_delete(ProdDataVal@) C CALLP QxmlDOM_Element_delete(ChildElem@) C CALLP QxmlDOM_Node_delete(child@) OK. At this point I have this situation in memory: root | parent1(....) -previosly added node | parent2(....) -previosly added node | parent3(NodeTYPE=ELEMENT, NodeName='Sudionik', | ChildList(FirstChild(NodeTYPE=ELEMENT, NodeName='VBDI', | ChildList(FirstChild(NodeTYPE=TXT,NodeName='',NodeValue='someNumber',...) | ) | ),.....) | ) | NULL After some time structure will be loaded with data from DB2 file and will be ready for writtnig into stream file. I'll just writte piece of code that performs some of job (there is a lot of recursive calls and looping while writting so I expect that peopole who know anything abouth XML processing will understand this fiew line:)) ): *---Open stream file with code page (CCSID) 870 C EVAL fd=QxmlOpenNewOutputStream C (xmlFile2@: C 0: ErrNo@: 870) . . . . some code . . *---If curent node is TXT TYPE writte its value in STMF C WHEN NodeType =Qxml_TEXT_NOD C EVAL rtn=QxmlWriteOutputStream(fd: C NodeVal@:Qxml_INDOMSTR:0) OK. Everything described work fine. After creation of STMF I do next thing. With CPYFRMSTMF comand I copy STMF in DB2 file with one field and CCSID 870 and after that copy DB2 file into new stream file with codepage parm set to *PCASCII. Well I'm shame (it's stupid) but it is only way the thing works. CL that do all jaob is next: PGM call pgm(createxml) parm('newXML.xml') clrpfm vbigor/vbecmcbucd cpyfrmstmf + fromstmf('newXML.xml') + tombr('/qsys.lib/v****.lib/vbecmcbucd.file+ /vbecmcbucd.mbr') mbropt(*add) + ENDLINFMT(*ALL) cpytostmf + frommbr('/qsys.lib/v****.lib/vbecmcbucd.file+ /vbecmcbucd.mbr') + tostmf('CLBF01.xml') STMFCODPAG(*PCASCII) + ENDLINFMT(*CRLF) ENDPGM CLBF01.xml is readable on windows platform and had all correct characters used by 1250 code page. You can ask why I didn't change 870 CCSID in code in 1250 when I'm openinf stream file. I did but after that program crashes down with message that system is not allocated memory properly. I read some examples that suggest using of qXMLTranscode procedure, but what should I do with it when output stream is opened for writting in 870 CCSID. And one more thing, I implemented reverse process of loading data from windows-1250 encoded XML file in db2 with conversion in 870 CCSID and it works fine without any lost characters. If anyone knows something that will help me, writte... Thanks very much, Igor.
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.