Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Read a XML document in COBOL
Hey,

I'm trying to read an XML document (see at the end of the page) in
COBOL (I'm using PerCobol). First I tried to read it doing this:

perform until einde = 1
display "|||"lijn"|||"
UNSTRING lijn DELIMITED BY '>' INTO
root

END-UNSTRING
MOVE root(2:2) TO rootTemp
UNSTRING root DELIMITED BY '<' INTO
vuller,element

END-UNSTRING

But thats a lot of work and its hard, now I heard that you can do it a
lot easier??? But how? I didn't find any informatie. So if you can help
me reading this document I thank you!!!

Gtz

Olivier



<?xml version="1.0" encoding="UTF-8"?>
<studentenlijst>
<student>
<!--student bevat steeds 1 studentnummer, 1 naam, 1 voornaam, 1 email,
1 studiejaar, 1 paswoord en mogelijk 1 projecten tag en wel in die
volgorde-->
<studentnummer>20060001</studentnummer>
<naam>Janssens</naam>
<voornaam>Pieter</voornaam>
<email>Pieter.Janssens@hogent.be</email>
<studiejaar>1</studiejaar>
<paswoord>abcdefg</paswoord>
<!-- tag projecten komt voor enkel en alleen als de student een
geindividualiseerd studietraject volgt-->
<projecten>
<!-- id komt overeen met het projectid uit de tabel projecten-->
<project id="1"/>
<project id="10"/>
</projecten>
</student>
<student>
<studentnummer>20060002</studentnummer>
<naam>Janssens</naam>
<voornaam>An</voornaam>
<email>An.Janssens@hogent.be</email>
<studiejaar>1</studiejaar>
<paswoord>xyzuvw</paswoord>
</student>
</studentenlijst>


Report this thread to moderator Post Follow-up to this message
Old Post
olivierdeman@gmail.com
11-24-06 12:55 PM


Re: Read a XML document in COBOL
olivierdeman@gmail.com wrote:
> Hey,
>
> I'm trying to read an XML document (see at the end of the page) in
> COBOL (I'm using PerCobol).

I'm not familiar with PerCobol - someone else may be able to chime in
with specifics.  If you're running in a Windows environment, you may be
able to use the available Microsoft XML parser to create an XML document
object.  I've never done that, but I know I've seen some examples of
similar code here.  You might try searching the archives for code
examples.  :)

--
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~
~   /   \  /         ~        Live from Montgomery, AL!       ~
~  /     \/       o  ~                                        ~
~ /      /\   -   |  ~          daniel@thebelowdomain         ~
~ _____ /  \      |  ~      http://www.djs-consulting.com     ~
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
~ GEEKCODE 3.12 GCS/IT d s-:+ a C++ L++ E--- W++ N++ o? K- w$ ~
~ !O M-- V PS+ PE++ Y? !PGP t+ 5? X+ R* tv b+ DI++ D+ G- e    ~
~ h---- r+++ z++++                                            ~
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~

"Who is more irrational?  A man who believes in a God he doesn't see, or
a man who's offended by a God he doesn't believe in?" - Brad Stine

Report this thread to moderator Post Follow-up to this message
Old Post
LX-i
11-24-06 11:55 PM


Re: Read a XML document in COBOL
olivierdeman@gmail.com wrote:

> I'm trying to read an XML document (see at the end of the page) in
> COBOL (I'm using PerCobol). First I tried to read it doing this:
>
> perform until einde = 1
>                    display "|||"lijn"|||"
>                   UNSTRING lijn DELIMITED BY '>' INTO
>                         root
>
>                   END-UNSTRING
>                   MOVE root(2:2) TO rootTemp
>                   UNSTRING root DELIMITED BY '<' INTO
>                         vuller,element
>
>                   END-UNSTRING

It's no where near as easy as that.  You need to use a proper parser.
Given it is PerCobol you should be able to use a Java parser.  However
if you want to do it in Cobol you may like to start with one that I
pulled off the net and tidied up a bit:

IDENTIFICATION DIVISION.
PROGRAM-ID.             xmlparse.

*    xmlparse.LST
*    \xml\xml.cbl

*AUTHOR. Miami-Dade Community College.
*DATE-WRITTEN.  July, 2000.
*DATE-COMPILED.
*REMARKS.
*
*    LAST CHANGE:  09/12/00 12:02:24 SAHWC
*
*    This program will parse any valid XML document into its
*    component parts.
*

ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.

DATA DIVISION.
FILE SECTION.

WORKING-STORAGE SECTION.

01  FILLER.
05  FILLER                  PIC X(32) VALUE
'WORKING-STORAGE FOR XMLPARSE>>>:'.
05  Wk-Index                PIC S9(9)           COMP SYNC.
05  Wk-Index-1              PIC S9(9)           COMP SYNC.
05  Wk-Index-2              PIC S9(9)           COMP SYNC.
05  Wk-Start-Index          PIC S9(9)           COMP SYNC.
05  Wk-Seq-Nbr              PIC S9(9)           COMP SYNC.
05  Ending-Ptr              PIC S9(9)           COMP SYNC.
05  Base-Ptr                PIC S9(9)           COMP SYNC.
05  Wk-Length               PIC S9(4)           COMP SYNC.
05  Entity-Length           PIC S9(4)           COMP SYNC.
05  Result                  PIC 9.
05  Wk-Find-Char            PIC X.
05  Skip-White-Space-Check  PIC X.
05  Wk-Entity               PIC X(6).
05  FILLER REDEFINES Wk-Entity.
10  Wk-Entity-X         PIC X     OCCURS 6 TIMES.
05  Wk-Markup-Character     PIC X.
05  Attr-Name               PIC X(50).
05  Elem-Name               PIC X(50).
05  Data-Value              PIC X(1010).
05  FILLER REDEFINES Data-Value.
10  Data-Value-X        PIC X     OCCURS 1010 TIMES.
05  Name-Value              PIC X(1000).
05  FILLER REDEFINES Name-Value.
10  Name-Value-X        PIC X     OCCURS 1000 TIMES.
05  FILLER REDEFINES Name-Value.
10  FILLER              PIC X(5).
88  Name-Value-Start-With-CData
VALUE 'CDATA'.
05  Wk-End-of-Msg-Switch    PIC X.
88  Wk-End-of-Msg                 VALUE '1'.
05  Wk-Found-Switch         PIC X.
88  Wk-Found                      VALUE '1'.
05  Wk-Parsing-Error-Switch PIC X.
88  Wk-Parsing-Error              VALUE '1'.

01  ToUpper.
03  Char-Comp               PIC 9(4) COMP SYNC.
03  FILLER REDEFINES Char-Comp.
05  FILLER              PIC X.
05  Char-X              PIC X.

01  FILLER.
*    ASCII values
05  LEFT-BRACKET            PIC X     VALUE "<".
05  RITE-BRACKET            PIC X     VALUE ">".
05  VALUE-TAB               PIC X     VALUE x"09".
05  VALUE-LF                PIC X     VALUE x"0A".
05  VALUE-CR                PIC X     VALUE x"0D".
05  VALUE-QUOTE             PIC X     VALUE QUOTE.

05  FILLER                  PIC S9(4) VALUE ZERO COMP SYNC.

05  TTL-Acceptable-Chars    PIC S9(4) VALUE 66 COMP SYNC.
05  TTL-Acceptable-First-Chars
PIC S9(4) VALUE 53 COMP SYNC.

05  Acceptable-Chars        PIC X(66) VALUE

 '_ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijkl
mnopqrstuvwxyz012
-        '3456789-.:'.
05  FILLER REDEFINES Acceptable-Chars.
10  Acceptable-Chars-X  PIC X     OCCURS 66 TIMES.

05  TTL-Entity-Reference    PIC S9(4) VALUE 5  COMP SYNC.
05  Entity-Reference.
10  FILLER              PIC X(7)  VALUE '&gt;  >'.
10  FILLER              PIC X(7)  VALUE '&lt;  <'.
10  FILLER              PIC X(7)  VALUE '& &'.
10  FILLER.
15  FILLER          PIC X(6)  VALUE '''.
15  FILLER          PIC X     VALUE QUOTE.
10  FILLER              PIC X(7)  VALUE '""'.
05  FILLER REDEFINES Entity-Reference.
10  FILLER                        OCCURS 5 TIMES.
15 Entity-Reference-X  PIC X(6).
15 Markup-Character    PIC X.

05  Result-Table.
10  FILLER              PIC X(3)  VALUE '1  '.
10  FILLER              PIC X(3)  VALUE '1  '.
10  FILLER              PIC X(3)  VALUE '111'.
10  FILLER              PIC X(3)  VALUE '1 1'.
10  FILLER              PIC X(3)  VALUE '   '.
10  FILLER              PIC X(3)  VALUE '   '.
10  FILLER              PIC X(3)  VALUE '111'.
10  FILLER              PIC X(3)  VALUE '111'.
10  FILLER              PIC X(3)  VALUE '111'.
05  FILLER REDEFINES Result-Table.
10  FILLER                        OCCURS 9 TIMES.
15  FILLER          PIC X.
88  Elem-Name-Required    VALUE '1'.
15  FILLER          PIC X.
88  Attr-Name-Required    VALUE '1'.
15  FILLER          PIC X.
88  Data-Value-Required   VALUE '1'.

LINKAGE SECTION.

COPY "xmlparse.ws".     *> \az\include\xmlparse.ws

PROCEDURE DIVISION USING XML-Interface
XML-Document

Report this thread to moderator Post Follow-up to this message
Old Post
Richard
11-24-06 11:55 PM


Re: Read a XML document in COBOL
Richard wrote:

>        LINKAGE SECTION.
>
>            COPY "xmlparse.ws".     *> \az\include\xmlparse.ws
>
>        PROCEDURE DIVISION USING XML-Interface
>                                 XML-Document
>                                 .

01  XML-Interface.
*    05  XML-Occurs              PIC 9(9)    VALUE 20000.
05  XML-Occurs              PIC 9(9).
05  XML-Length              PIC 9(9).
05  XML-Reserved.
10  Save-Index          PIC 9(9).
10  Char-Ptr            PIC 9(9).
10  State               PIC 99.
10  Save-Elem-Name      PIC X(50).
10  FILLER              PIC X(30).
05  XML-Parsed-Area.
10  XML-Return-Code     PIC 9.
10  XML-Element-Name    PIC X(50).
10  XML-Attribute-Name  PIC X(50).
10  XML-Data-Value      PIC X(1000).

01  XML-Document.
05  XML-Document-X          PIC X       OCCURS 20000.

*
 ========================================
========================
*    end of source code
*  ========================================
========================


Report this thread to moderator Post Follow-up to this message
Old Post
Richard
11-25-06 02:55 AM


Re: Read a XML document in COBOL
Richard wrote:

Test program

IDENTIFICATION DIVISION.
PROGRAM-ID.             xmltest.

*    xmltest.lst
*    xmlparse.cbl
*    \az\xmltest.dta
*

ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SPECIAL-NAMES.

INPUT-OUTPUT SECTION.
FILE-CONTROL.

SELECT XML-File
ASSIGN       XML-Name
ORGANIZATION LINE SEQUENTIAL
FILE STATUS  File-Status

Report this thread to moderator Post Follow-up to this message
Old Post
Richard
11-25-06 02:55 AM


Re: Read a XML document in COBOL
<olivierdeman@gmail.com> wrote in message
news:1164365982.752040.128040@f16g2000cwb.googlegroups.com...
> Hey,
>
> I'm trying to read an XML document (see at the end of the page) in
> COBOL (I'm using PerCobol). First I tried to read it doing this:
>
> perform until einde = 1
>                   display "|||"lijn"|||"
>                  UNSTRING lijn DELIMITED BY '>' INTO
>                        root
>
>                  END-UNSTRING
>                  MOVE root(2:2) TO rootTemp
>                  UNSTRING root DELIMITED BY '<' INTO
>                        vuller,element
>
>                  END-UNSTRING
>
> But thats a lot of work and its hard, now I heard that you can do it a
> lot easier??? But how? I didn't find any informatie. So if you can help
> me reading this document I thank you!!!

If you are running on a Microsoft platform and think that re-inventing the
wheel or re-discovering fire is a waste of your time, take a look at this...
http://www.chilkatsoft.com/ChilkatXml.asp

It's free, and is marginally better (in my opinion) than the Microsoft
component that is already on your machine.

Pete.

<snipped interesting Dutch XML file>



Report this thread to moderator Post Follow-up to this message
Old Post
Pete Dashwood
11-25-06 08:55 AM


Re: Read a XML document in COBOL
"Richard" <riplin@Azonic.co.nz> wrote in message
news:1164394338.648474.306120@l39g2000cwd.googlegroups.com...
>
> olivierdeman@gmail.com wrote:
> 
>
> It's no where near as easy as that.  You need to use a proper parser.
> Given it is PerCobol you should be able to use a Java parser.  However
> if you want to do it in Cobol you may like to start with one that I
> pulled off the net and tidied up a bit:
>
<snipped very lengthy code>

I hope you use this as a component, Richard... :-)

Pete.



Report this thread to moderator Post Follow-up to this message
Old Post
Pete Dashwood
11-25-06 08:55 AM


Re: Read a XML document in COBOL
Pete Dashwood wrote:

> I hope you use this as a component, Richard... :-)

I did play with the code some years ago when learning how to deal with
XML but I do my XML processing in C with libxml2 or Python as
appropriate.


Report this thread to moderator Post Follow-up to this message
Old Post
Richard
11-25-06 08:55 AM


Re: Read a XML document in COBOL
Read the "proposed Technical Report" for native COBOL XML support in ANSI/IS
O
COBOL at:
http://www.cobolstandard.info/j4/files/06-0200.doc

This is similar (not identical) to what Micro Focus already supports.

IBM has a very different model - but also XML-specific.   Check out:
http://publibz.boulder.ibm.com/cgi-...KS/IGY3PG31/5.0

I don't know what (if anything) PerCOBOL offers.  You might want to contact 
them
and ask them if they have looked at either of the "models" listed above.

--
Bill Klein
wmklein <at> ix.netcom.com
<olivierdeman@gmail.com> wrote in message
news:1164365982.752040.128040@f16g2000cwb.googlegroups.com...
> Hey,
>
> I'm trying to read an XML document (see at the end of the page) in
> COBOL (I'm using PerCobol). First I tried to read it doing this:
>
> perform until einde = 1
>                   display "|||"lijn"|||"
>                  UNSTRING lijn DELIMITED BY '>' INTO
>                        root
>
>                  END-UNSTRING
>                  MOVE root(2:2) TO rootTemp
>                  UNSTRING root DELIMITED BY '<' INTO
>                        vuller,element
>
>                  END-UNSTRING
>
> But thats a lot of work and its hard, now I heard that you can do it a
> lot easier??? But how? I didn't find any informatie. So if you can help
> me reading this document I thank you!!!
>
> Gtz
>
> Olivier
>
>
>
> <?xml version="1.0" encoding="UTF-8"?>
> <studentenlijst>
> <student>
> <!--student bevat steeds 1 studentnummer, 1 naam, 1 voornaam, 1 email,
> 1 studiejaar, 1 paswoord en mogelijk 1 projecten tag en wel in die
> volgorde-->
> <studentnummer>20060001</studentnummer>
> <naam>Janssens</naam>
> <voornaam>Pieter</voornaam>
> <email>Pieter.Janssens@hogent.be</email>
> <studiejaar>1</studiejaar>
> <paswoord>abcdefg</paswoord>
> <!-- tag projecten komt voor enkel en alleen als de student een
> geindividualiseerd studietraject volgt-->
> <projecten>
> <!-- id komt overeen met het projectid uit de tabel projecten-->
> <project id="1"/>
> <project id="10"/>
> </projecten>
> </student>
> <student>
> <studentnummer>20060002</studentnummer>
> <naam>Janssens</naam>
> <voornaam>An</voornaam>
> <email>An.Janssens@hogent.be</email>
> <studiejaar>1</studiejaar>
> <paswoord>xyzuvw</paswoord>
> </student>
> </studentenlijst>
>



Report this thread to moderator Post Follow-up to this message
Old Post
William M. Klein
12-11-06 11:56 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Cobol archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 08:11 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.