I have XML file that's stored in the clob column of the table in DB.
<?xml version="1.0" encoding="UTF-8"?>
<document>
<row>
<organization>asdklfjas;kldfj;LASKJFAS</organization>
<phones>sjhdfhjaghjskfg</phones>
<persons>hkjg</persons>
</row>
</document>
I'm using DBMS_XMLDOM
package for parse it.
declare
v_clob clob;
v_doc dbms_xmldom.domdocument;
begin
...
v_doc := dbms_xmldom.newdomdocument(v_clob);
v_domelement := dbms_xmldom.getdocumentelement(v_doc);
...
end;
I need simply to get value from some element, for example <persons>
. How can I do it?
There is also the option to use XslProcessor functions together with XPath:
DECLARE
v_Clob CLOB;
v_Doc XmlDom.DomDocument;
v_RootNode XmlDom.DomNode;
v_Value VARCHAR2(128);
BEGIN
...
v_Doc := XmlDom.NewDomDocument(v_Clob);
v_RootNode := XmlDom.MakeNode(XmlDom.GetDocumentElement(v_Doc));
v_Value := XmlDom.GetNodeValue(
XslProcessor.SelectSingleNode(v_RootNode, '/document/row[1]/persons/text()'));
...
END;
I found what I was searching:
...
v_doc := dbms_xmldom.newdomdocument(v_clob);
v_nodelist := dbms_xmldom.getelementsbytagname(v_doc, 'persons');
v_node := dbms_xmldom.getfirstchild(dbms_xmldom.item(v_nodelist, 0));
v_person := dbms_xmldom.getnodevalue(v_node);
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With