The GETNODEVALUE function returns the string value of a specified node. It can be used to read the content of text nodes or element nodes.
Applicability
This content applies only to OceanBase Database Enterprise Edition. OceanBase Database Community Edition provides only the MySQL-compatible mode.
Note
For V4.4.2, this subprogram is available starting with OceanBase Database V4.4.2 BP2.
Syntax
DBMS_XMLDOM.getNodeValue (
node IN DBMS_XMLDOM.DOMNODE);
Parameters
Parameter |
Description |
|---|---|
| node | The DBMS_XMLDOM.DOMNODE handle to read. |
Return value
String value of the node, of type VARCHAR2.
Usage instructions
- For text or CDATA nodes: directly return their text content.
- For element nodes: You can also call this function directly. According to the DOM specification, its behavior is equivalent to retrieving the content of the first child node (usually
#text), making it suitable for obtaining the text value of a leaf element.
Examples
This example uses an explicit approach to locate the text child node: first, use GETCHILDNODES and ITEM to obtain the #text node, then call GETNODEVALUE to read 'hello'. If you already hold a leaf element node, you can skip the child node traversal and directly call GETNODEVALUE on that leaf element node.
-- Declare parser and document handle variables
DECLARE
p DBMS_XMLPARSER.PARSER;
doc DBMS_XMLDOM.DOMDOCUMENT;
nl DBMS_XMLDOM.DOMNODELIST;
n DBMS_XMLDOM.DOMNODE;
v VARCHAR2(32767);
BEGIN
-- Create a parser instance
p := DBMS_XMLPARSER.NEWPARSER;
-- Parse the XML document in the parser.
DBMS_XMLPARSER.PARSECLOB(p, '<root><item>hello</item></root>');
-- Get the DOMDocument handle of an XML document
doc := DBMS_XMLPARSER.GETDOCUMENT(p);
-- Release parser instance
DBMS_XMLPARSER.FREEPARSER(p);
-- Get the list of all elements named "item" in the XML document
nl := DBMS_XMLDOM.GETELEMENTSBYTAGNAME(doc, 'item');
-- Gets the first element in the list
n := DBMS_XMLDOM.ITEM(nl, 0);
-- Gets the list of child nodes of an element.
nl := DBMS_XMLDOM.GETCHILDNODES(n);
-- Gets the first child node in the list (#text text node).
n := DBMS_XMLDOM.ITEM(nl, 0);
-- Get the node value 'hello'
v := DBMS_XMLDOM.GETNODEVALUE(n);
-- Release XML Document Resources
DBMS_XMLDOM.FREEDOCUMENT(doc);
END;
/
