View previous topic :: View next topic
|
Author |
Message |
Saroj Tripathy
New User
Joined: 05 Mar 2007 Posts: 23 Location: India
|
|
|
|
My requiremnt is like this I have a string of say 5000 chars length.
the data it has is like below
[fgtyihcbc<doc>iiiiiiggggggg</doc>iiiiiiii<doc>iiiiitttttffffffffffffff</doc>kkk]
I want to replace all chars present outside <doc> and </doc> with spaces.
what should be my approch ??? |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
I had the same problem.
I used a perform loop with reference modification to squeeze in place the junk out. |
|
Back to top |
|
|
Saroj Tripathy
New User
Joined: 05 Mar 2007 Posts: 23 Location: India
|
|
|
|
The problem is the <doc> and </doc> may appear anywhere in the string. so i dont think i can use reference modification. |
|
Back to top |
|
|
agkshirsagar
Active Member
Joined: 27 Feb 2007 Posts: 691 Location: Earth
|
|
|
|
Nested tags possible? I mean
<doc>hhh <doc> hhhhh </doc> hhh</doc>
IF NOT
You can simply replace data between </doc> and <doc> and it is possible with reference modification. |
|
Back to top |
|
|
Saroj Tripathy
New User
Joined: 05 Mar 2007 Posts: 23 Location: India
|
|
|
|
No nested tags are not possible.
Can you please provide the syntax of how to replace data between </doc> and <doc> using reference modification.
thanks... |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
Saroj Tripathy wrote: |
Can you please provide the syntax of how to replace data between </doc> and <doc> using reference modification. |
Replace or squeeze out?
Replace with what? |
|
Back to top |
|
|
shankar.v
Active User
Joined: 25 Jun 2007 Posts: 196 Location: Bangalore
|
|
|
|
Code: |
SET WF-START-POSITION-NOT FOUND TO TRUE
SET WF-END-POSITION-NOT-FOUND TO TRUE
PERFORM VARYING I FROM 1 BY 1 UNTIL I = LENGTH OF WS-STRING
IF WS-STRING(I:5) = '<DOC>'
SET WF-START-POSITION-FOUND TO TRUE
MOVE I TO WS-START-POSITION
COMPUTE I = I + 5
END-IF
IF WS-STRING(I:6) = '</DOC>
SET WF-END-POSITION-FOUND TO TRUE
COMPUTE I = I + 5
MOVE I TO WS-END-POSITION
END-IF
IF WF-START-POSITION-FOUND AND WF-END-POSITION-FOUND
MOVE WS-STRING(WS-START-POSITION:WS-END-POSITION) TO
WS-FINAL-STRING
SET WF-START-POSITION-NOT FOUND TO TRUE
SET WF-END-POSITION-NOT-FOUND TO TRUE
COMPUTE I = I + 1
END-IF
END-PERFORM |
|
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
shankar.v
you code would work if he only has one pair of <doc></doc>, and you used the lower case for doc. XML standards dictate lowercase, not uppercase. |
|
Back to top |
|
|
Saroj Tripathy
New User
Joined: 05 Mar 2007 Posts: 23 Location: India
|
|
|
|
thanks Shankar.
your code looks cool .
to all the members who contributed, thanks for helping me out. |
|
Back to top |
|
|
|