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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Formula help to manipulate XML

Status
Not open for further replies.

priyanthan

Programmer
Jul 27, 2008
70
CA
I'm trying to extract certain values from XML tags.
for example i have the following XML
<Trans>Withd,Inq,TrfFrm</Trans>

I need to display
Withd
Inq
TrfFrm.

I tried this formula:

/*{@t2} = <Trans>Withd,Inq,TrfFrm</Trans> */

stringvar array Comms := split({@t2},"/><");
numbervar i;
numbervar j := ubound(Comms);
stringvar TStr := "";
for i := 2 to j do(
TStr:= TStr + extractstring(Comms,""," ")+chr(13));
if len(TStr)>= 2 then
left(TStr,len(TStr)-2) else
TStr

but the result is
Inq
TrfFrm
I'm missing the first string. i don't know what i'm missing here. can anyone please help me.

working with CR11 and db2.
 
is there a reason i don't see for this "for i := 2 to j" instead of this "for i := 1 to j"

Why start with 2 instead of 1?
 
Yes your correct. my mistake. thanks for pointing me that.

i have another issue, hope i can post in there rather than in a new one.

Now that i got i want, but the string are not complete,
i need to show like this;

If its Withd then i'll have to show as Withdrawal or
Inq should be Inquiry

Can you please tell me a better way to do this,

Appreciate your help.
 
You did not specify a alternate value for TrfFrm, so it is not included below.
This is untested and off the top of my head, so apologies if i missed something or there is an easier way.

Replace this:
TStr:= TStr + extractstring(Comms,""," ")+chr(13));

With this:
IF extractstring(Comms,""," ")="Withd"
then TStr := TStr + "Withheld"+chr(13)
else
(IF extractstring(Comms,""," ")="Inq"
then TStr := TStr + "Inquiry"+chr(13)
else TStr := TStr +extractstring(Comms,""," ")+chr(13));

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top