The getElementsByTagName function is used to find all element nodes with the tag name tag_name in a depth-first manner throughout the subtree of the specified document doc, and returns them as a list of 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.getElementsByTagName (
doc IN DBMS_XMLDOM.DOMDOCUMENT,
tag_name IN VARCHAR2);
Parameters
Parameter |
Description |
|---|---|
| doc | The DBMS_XMLDOM.DOMDOCUMENT handle of the XML document. |
| tag_name | The element tag name to match. A value of '*' matches any element tag. |
Return value
Matches the DBMS_XMLDOM.DOMNODELIST element nodes.
Usage instructions
An empty return list indicates no matching elements were found. To process the traversal results, use GETLENGTH and ITEM; to read an element's text, you can further call GETNODEVALUE.
Examples
This example uses the DBMS_XMLPARSER system package to parse an XML document and obtain a DOMDOCUMENT handle. Then, it uses the DBMS_XMLDOM system package to get the DOMNODELIST handle of the XML document, and retrieve a list of all elements named "item" and a list of all elements in the XML document:
-- Declare parser and document handle variables
DECLARE
p DBMS_XMLPARSER.PARSER;
doc DBMS_XMLDOM.DOMDOCUMENT;
nl DBMS_XMLDOM.DOMNODELIST;
BEGIN
-- Create a parser instance
p := DBMS_XMLPARSER.NEWPARSER;
-- Parse the XML document in the parser.
DBMS_XMLPARSER.PARSECLOB(p, '<root><item/><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');
-- Get list of all elements in an XML document
nl := DBMS_XMLDOM.GETELEMENTSBYTAGNAME(doc, '*');
-- Release XML Document Resources
DBMS_XMLDOM.FREEDOCUMENT(doc);
END;
/
