Problem: “I am having trouble parsing XML in PL/SQL using the XMLType.extract() function. I've done this dozens of times in the past with no issue - what am I doing wrong?”
ORA-30625: Method Dispatch on NULL SELF Argument Is Disallowed
Solution: Your XML tags are defined within a namespace. You need to pass the “nsmap” parameter to the extract function.
Oracle Database > Release 21
Code Example
Take a look at this XML - notice how each tag name starts with ns1:
.
<ns1:root xmlns:ns1="http://www.example.com/">
<ns1:childNode>12345678</ns1:childNode>
</ns1:root>
This PL/SQL shows how to create the nsmap
parameter and extract XML when tags are defined with a namespace.
DECLARE
l_raw_xml VARCHAR2(4000) := '
<ns1:root xmlns:ns1="http://www.example.com/">
<ns1:childNode>ChildNode - Contents</ns1:childNode>
</ns1:root>';
l_xml XMLType;
l_nsmap VARCHAR2(255);
BEGIN
l_xml := XMLType(l_raw_xml);
l_nsmap := 'xmlns="' || l_xml.getNamespace || '"';
dbms_output.put_line(
l_xml.existsnode(xpath => '/root/childNode',
nsmap => l_nsmap)
);
dbms_output.put_line(
l_xml.extract(xpath => '/root/childNode/text()',
nsmap => l_nsmap).getstringval()
);
END;
When you try to extract the xml with just the xpath parameter you get an error.
ORA-30625: Method Dispatch on NULL SELF Argument Is Disallowed
Real documentation on XML and namespaces can be found here.