Capture value btwn XML tags, split it and use it elsewhere
Posted: Wed May 28, 2008 12:42 am
I am trying to do the following. Search for a value held between a pair of XML tags(<ENVELOPE_PARM><VALUE>) then take that value and split it into two parts and then use them elsewhere in the xml file. Also I need to then overwrite that original value with one of the two parts.
So if I get this in:-
<ENVELOPE>
<CONTROL_NUMBER>321</CONTROL_NUMBER>
<FUNCTION>0</FUNCTION>
<SENDER_ID>Company X</SENDER_ID>
<RECEIVER_ID>Company Y</RECEIVER_ID>
<ENVELOPE_PARM>
<NAME>LookupAlias</NAME>
<VALUE>ACBTYPE</VALUE>
</ENVELOPE_PARM>
</ENVELOPE>
I need to search for the value given between <VALUE> and </VALUE> within the <ENVELOPE_PARM> and then capture that value and split it into two...part A which will the first 2-4 chars and part B that can either be BTYPE or ATYPE. The first 2-4 chars varies and could be anything up to 100 different values (eg could be AC as per above or ABCD or WXYZ or PQ etc). I need to then output part one in the RECEIVER_ID field and part two in the SENDER_ID field. I also need to overwrite the VALUE with whatever part two is. Therefore I should get out from the above this:-
<ENVELOPE>
<CONTROL_NUMBER>321</CONTROL_NUMBER>
<FUNCTION>0</FUNCTION>
<SENDER_ID>BTYPE</SENDER_ID>
<RECEIVER_ID>AC</RECEIVER_ID>
<ENVELOPE_PARM>
<NAME>LookupAlias</NAME>
<VALUE>BTYPE</VALUE>
</ENVELOPE_PARM>
</ENVELOPE>
Obviously some restrict needs to be done but I'm struggling with the capture and split of the variable part. Can you give any pointers please?
many thanks
So if I get this in:-
<ENVELOPE>
<CONTROL_NUMBER>321</CONTROL_NUMBER>
<FUNCTION>0</FUNCTION>
<SENDER_ID>Company X</SENDER_ID>
<RECEIVER_ID>Company Y</RECEIVER_ID>
<ENVELOPE_PARM>
<NAME>LookupAlias</NAME>
<VALUE>ACBTYPE</VALUE>
</ENVELOPE_PARM>
</ENVELOPE>
I need to search for the value given between <VALUE> and </VALUE> within the <ENVELOPE_PARM> and then capture that value and split it into two...part A which will the first 2-4 chars and part B that can either be BTYPE or ATYPE. The first 2-4 chars varies and could be anything up to 100 different values (eg could be AC as per above or ABCD or WXYZ or PQ etc). I need to then output part one in the RECEIVER_ID field and part two in the SENDER_ID field. I also need to overwrite the VALUE with whatever part two is. Therefore I should get out from the above this:-
<ENVELOPE>
<CONTROL_NUMBER>321</CONTROL_NUMBER>
<FUNCTION>0</FUNCTION>
<SENDER_ID>BTYPE</SENDER_ID>
<RECEIVER_ID>AC</RECEIVER_ID>
<ENVELOPE_PARM>
<NAME>LookupAlias</NAME>
<VALUE>BTYPE</VALUE>
</ENVELOPE_PARM>
</ENVELOPE>
Obviously some restrict needs to be done but I'm struggling with the capture and split of the variable part. Can you give any pointers please?
many thanks