Rather than trying to modify the XML string to remove the namespace, you can incorporate that into your XML query. OldProgrammer already showed how to do that with the deprecated extractValue()
function, but you can do the same thing with the XMLTable you asked about:
FUNCTION XMLTEST (P_XML VARCHAR2) RETURN VARCHAR2 AS
V_FLAG VARCHAR2(30);
BEGIN
SELECT P.boolean
INTO V_FLAG
FROM xmltable(xmlnamespaces(default 'http://SOAPwebservice.com/WebServices/Methods'),
'/boolean' passing xmltype(P_XML)
columns boolean VARCHAR2(30) PATH '.') P;
RETURN V_FLAG;
END XMLTEST;
Or - as you're expected a single node, and will get an error from the XMLTable version if there are multiples anyway - an XMLQuery:
SELECT XMLQuery(
'declare default element namespace "http://SOAPwebservice.com/WebServices/Methods"; (: :)
/boolean/text()'
passing xmltype(P_XML)
returning content).getStringVal()
INTO V_FLAG
FROM dual;
Read more about XMLTable and XMLQuery, and how they handle namespaces.
It's also possible to wildcard the XPath:
SELECT XMLQuery('/*:boolean/text()'
passing xmltype(P_XML)
returning content).getStringVal()
INTO V_FLAG
FROM dual;
With your formatted XML string the extracted value is more than just the string 'false'
- it has leading and trailing spaces and newline characters, which you could then strip out if necessary. If your real XML has <boolean>false</boolean>
with no extra whitespace then that isn't necessary, of course, and your v_flag
only needs to be five characters long.
You don't need to do this in PL/SQL, but that seems to be a requirement you are imposing.