Welcome Serena Central users! CLICK HERE
The migration of the Serena Central community is currently underway. Be sure to read THIS MESSAGE to get your new login set up to access your account.
picci Absent Member.
Absent Member.
4039 views

C$XML translation to utf-8 encoding

Jump to solution

Hi all, i want to write with C$XML the following string to an xml: "1.223,36 €". The problem comes obviously with the euro symbol.

I initialize the parser setting encoding to "UTF-8"  

call "C$XML" using CXML-SET-ENCODING export-parser "UTF-8".

I observed that on the runtime side the euro symbol is correctly encoded with the ascii code 128 (i saw it using function ord(), 129 - 1). When i create the xml and open it with notepad++ in utf-8 encoding i see no symbol where the € should be. Looking at it with an hexadecimal editor i see that there are 2 bytes allocated where the € should be and their content is c2 80 or, in decimal, 194 128. I found on wikipedia that the encoding of € in unicode is 3 bytes E2 82 AC.


I also tried to set the "us-ascii" encoding with CXML-SET-ENCODING but it doesn't work; with this encoding i would expect an header like <?xml version="1.0" encoding="us-ascii" standalone="no"?> while what i obtain is <?xml version="1.0" standalone="no"?> an the actual encoding is still the same as when i set "utf-8".

Can you give me some information on how the encoding works?

I verified this with runtime 9.0.1 and 9.1.1

Thank you,

Luca

Tags (3)
0 Likes
1 Solution

Accepted Solutions
Micro Focus Expert
Micro Focus Expert

RE: C$XML translation to utf-8 encoding

Jump to solution

Try this:

identification division.

program-id. xml-euro.

author.

remarks.  

environment division.

input-output section.

file-control.

data division.

file section.  

working-storage section.

copy "acucobol.def".    

01 key-pressed pic 9(4) is special-names crt status.

01 hParser usage handle.

01 hRicette usage handle.

01 hTestata usage handle.

01 hRicetta usage handle.

01 hPrestazione usage handle.

01 hTemp usage handle.

01 text-error pic x(50).

01 text-error-1 pic x(200).

01 num-error pic 9(3).

01 COMO-DESC pic x(50).

procedure division.

main-logic.

       call "c$xml" using cxml-new-parser

                    giving hParser

       call "C$XML" using CXML-SET-ENCODING

                    hParser

                    "ISO-8859-1".

       call "c$xml" using cxml-add-child

                          hParser

                          "Child1"

                    giving hRicette

       if hRicette not > 0

          move "error with Child1" to text-error

          perform print-errors

       end-if

       call "c$xml" using cxml-add-child

                          hRicette

                          "Test1"

                    giving hTestata

       if hTestata not > 0

          move "error with Test1" to text-error

          perform print-errors

       end-if

       MOVE "Test 9.0.0 with euro symbol €" TO COMO-DESC.

       INSPECT COMO-DESC REPLACING TRAILING SPACES BY x"00".

       CALL "C$XML" USING CXML-ADD-CHILD

                       hTestata

                       "Decription"

                       COMO-DESC

                       GIVING hTemp.      

       call "c$xml" using cxml-write-file

                           hParser

                          "testfile.xml"

       call "c$xml" using cxml-release-parser

                          hParser

stop run.

print-errors.

       call "c$xml" using cxml-get-last-error

                          text-error-1

                    giving num-error

       display message box

               text-error-1 x"0d0a" num-error

               title text-error

       stop run

       .

View solution in original post

0 Likes
4 Replies
Micro Focus Expert
Micro Focus Expert

RE: C$XML translation to utf-8 encoding

Jump to solution

Try this:

identification division.

program-id. xml-euro.

author.

remarks.  

environment division.

input-output section.

file-control.

data division.

file section.  

working-storage section.

copy "acucobol.def".    

01 key-pressed pic 9(4) is special-names crt status.

01 hParser usage handle.

01 hRicette usage handle.

01 hTestata usage handle.

01 hRicetta usage handle.

01 hPrestazione usage handle.

01 hTemp usage handle.

01 text-error pic x(50).

01 text-error-1 pic x(200).

01 num-error pic 9(3).

01 COMO-DESC pic x(50).

procedure division.

main-logic.

       call "c$xml" using cxml-new-parser

                    giving hParser

       call "C$XML" using CXML-SET-ENCODING

                    hParser

                    "ISO-8859-1".

       call "c$xml" using cxml-add-child

                          hParser

                          "Child1"

                    giving hRicette

       if hRicette not > 0

          move "error with Child1" to text-error

          perform print-errors

       end-if

       call "c$xml" using cxml-add-child

                          hRicette

                          "Test1"

                    giving hTestata

       if hTestata not > 0

          move "error with Test1" to text-error

          perform print-errors

       end-if

       MOVE "Test 9.0.0 with euro symbol €" TO COMO-DESC.

       INSPECT COMO-DESC REPLACING TRAILING SPACES BY x"00".

       CALL "C$XML" USING CXML-ADD-CHILD

                       hTestata

                       "Decription"

                       COMO-DESC

                       GIVING hTemp.      

       call "c$xml" using cxml-write-file

                           hParser

                          "testfile.xml"

       call "c$xml" using cxml-release-parser

                          hParser

stop run.

print-errors.

       call "c$xml" using cxml-get-last-error

                          text-error-1

                    giving num-error

       display message box

               text-error-1 x"0d0a" num-error

               title text-error

       stop run

       .

View solution in original post

0 Likes
Micro Focus Frequent Contributor
Micro Focus Frequent Contributor

RE: C$XML translation to utf-8 encoding

Jump to solution

Since you are using extend 9, another possible solution to this problem would be to employ XML Extensions to output your XML document.  XML Extensions is included with the extend 9 Development System, and, it is another option for providing support for XML documents in your COBOL programs.

Below is an example program that will output the Euro sign(€) into a UTF-8 encoded XML document using XML Extensions:

----------------------------------------------

      Identification Division.

      Program-Id.  XMLExt.

      Data Division.

      Working-Storage Section.

      01  COMO-DESC  pic x(50).

      Copy "lixmlall.cpy".

      Procedure Division.

      A.

          Display "XML Extensions Example Export".

          XML INITIALIZE.

          If Not XML-OK Go to Z End-If.

  MOVE "Test 9.0.0 with euro symbol €" TO COMO-DESC.

          XML EXPORT FILE

              COMO-DESC   *> reference to export source data item (input)

              "output.xml"       *> output document file name (input)

              "COMO-DESC".     *> model data name string (input)

          If Not XML-OK Go to Z End-If.

  Display "The contents of COMO-DESC are in output.xml".

          Display "Press a key to terminate:".

          accept omitted.  

  stop run.

      Z.

          Copy "lixmltrm.cpy".

          Display "Press a key to terminate:".                        

          accept omitted.

          Stop Run.

          Copy "lixmldsp.cpy".

      End Program  XMLExt.

----------------------------------------------

*In order to compile a program that uses XML Extensions, you will need to use the "-Ze" command line option, and, set the COPYPATH environment variable to the location of the XML Extensions directory, "xmlext", located in the extend 9 samples path.

**In order to execute a program that uses XML Extensions, you will need to load the XML Extensions library(xmlif.dll or libxmlif.so).

0 Likes
picci Absent Member.
Absent Member.

RE: C$XML translation to utf-8 encoding

Jump to solution

Codify with ISO-8859-1 works only with runtime > 9.1 but we need retrocompatibility. XML Extension is not a suitable solution as we need to compose our xml dinamically, in order to export the content of any kind of grid.

Thank you anyway.

0 Likes
Knowledge Partner
Knowledge Partner

RE: C$XML translation to utf-8 encoding

Jump to solution

Of course you are free to make your own judgement, but XML Extensions is highly capable in 'dynamic' situations.  The difference is that much of the work is transferred from the COBOL program to an XSLT stylesheet.  I would suggest that interested persons review A Collection of Xcentrisity Examples (available in the Product Documentation) for ways in which XML Extensions can be used to generate spreadsheets usable in Microsoft Excel or Open Office.  See also the Blog entry http://community.microfocus.com/microfocus/cobol/extend_and_acucobol/b/weblog/archive/2012/07/19/useful-information-about-xcentrisity-business-information-server.aspx.


Tom Morrison
Consultant

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.