kumarb
kumarb

Reputation: 535

read a tag from a string in XML format

in my procedure I am reading a blob message and after extracting it I am assigning that to a VARCHAR2.

Now since the variable is coming like below (XML format), I would like to read the value of a tag element like host. I have tried using substring function but result is not consistent as Host name string length is keep on changing..

Could you please suggest me some option to have this worked ..?

<fault>
<id>xxxxxxxxxfc709f06870000</id>
<host>***.***.com:2222</host>
<uri>**/**/**.***</uri>
<payload><?xml version="1.0" encoding="UTF-8"?>

Upvotes: 1

Views: 170

Answers (1)

WadimX
WadimX

Reputation: 317

You should use xmltype instead of VARCHAR2.

val xmltype; 
host VARCHAR2;

val := xmltype(varchar2_val); 
host := val.extract('/host/text()').getStringVal()

Upvotes: 1

Related Questions