Parsing XML attributes
GregorMMar 8 2012 — edited Mar 10 2012Hi.
I have the following example of XML structure :
create table xxx (xmlval xmltype);
insert into xxx values (xmltype('<?xml version="1.0" encoding="utf-8"?> <Records> <Card P1="10" P2="20" /> </Records>'));
I have written the following code :
declare
lx_xml_node xmltype;
l_str varchar2(100);
begin
select e.xmlval.extract('/Records/Card[1into lx_xml_node from xxx e;
select lx_xml_node.extract('/@Card/P1').getStringVal() into l_str from xxx e;
dbms_output.put_line(l_str);
end;
The problem is I cant get the value of P1 attibute (l_str IS NULL). Is there a way to extract P1 and P2 attribute from xml node? Any help or hint appreciated.
Thanks.