Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parsing strings

Status
Not open for further replies.

RonaldB

Programmer
Nov 28, 2000
196
0
0
US
Hi !
I have to build an algorithm for parsing an XML document.
Does anyone have any good ideas on how to browse thru a string, searching for specific texts, transferring bits of it to other fields, and such ? It need not be very generic, since the document is rather uniform.
 
It sounds like you may be able to use reference modification. This code was used to parse a generic file that contained information separated by a comma. Reference modification is formatted as follows: FIELD (LOCATION : LENGTH)

INITIALIZE COUNTERS.
MOVE 'N' TO FOUND-SWITCH.

PERFORM VARYING COUNTER FROM 1 BY 1 UNTIL
FOUND-SWITCH = 'Y'

IF INPUT-FILE-RECORD(COUNTER:1) = KN-COMMA
MOVE 'Y' TO FOUND-SWITCH
ELSE
ADD +1 TO COUNTER2
END-IF

END-PERFORM.

MOVE INPUT-FILE-RECORD(1:COUNTER2)
TO POLICY-PREFIX.

ADD +1 TO COUNTER.

MOVE INPUT-FILE-RECORD(COUNTER:10)

TO POLICY-NUMBER-OUT.

ADD +12 TO COUNTER

MOVE INPUT-FILE-RECORD(COUNTER:1)
TO ROLE-CODE-OUT.

WRITE REPORT-RECORD.

Hope that any of this may help!

s-)
 
This sounds suspiciously like homework, but as you already have one reply, here's another idea: try using the Inspect instruction if you have covered this. I think this is what your teacher will be looking for, and may be easier for you to programme than having to do your own loops adding to a counter each time.

i.e. INSPECT INPUT-FILE-RECORD TALLYING COUNTER For all characters before initial ","

Then INSPECT INPUT-FILE-RECORD (COUNTER:) TALLYING COUNTER-1 for......

also INSPECT INPUT-FILE-RECORD tallying COUNTER-2 For All "," will tell you how many commas there are in the file.

And don't forget to check for the end of INPUT-FILE-RECORD or your progamme will ABEND!
 
Both of you thanks for the reply !

Stringer: i can assure you that this is no homework ! I'm actually getting paid for it !

Greenguy71: reference modification sounds like a plan. I'll let you know when i've cracked it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top