DECLARE
orginal_xml xmltype;
extracted_xml xmltype;
BEGIN
orginal_xml := xmltype.createxml(
'
);
dbms_output.put_line( 'Orginal XML :' );
dbms_output.put_line(orginal_xml.getStringVal());
dbms_output.put_line( lpad('-',100, '-' ) );
extracted_xml := orginal_xml.extract('//students/student[ position() = 1 ]');
dbms_output.put_line( 'XPath Expression : ' || '//students/student[ position() = 1 ] ' );
dbms_output.put_line( extracted_xml.getStringVal() );
dbms_output.put_line( lpad('-',100, '-' ) );
extracted_xml := orginal_xml.extract('//students/student[ position() = last() ]/name/attribute::id');
dbms_output.put_line( 'XPath Expression : ' || '//students/student[ position() = last() ]/name/attribute::id' );
dbms_output.put_line( extracted_xml.getStringVal() );
END;
The output is
Orginal XML :
----------------------------------------------------------------------------------------------------
XPath Expression : //students/student[ position() = 1 ]
----------------------------------------------------------------------------------------------------
XPath Expression : //students/student[ position() = last() ]/name/attribute::id
1899
No comments:
Post a Comment