Reputation: 3781
I know this has been asked before, but I'm not able to monkey-see-monkey-do with my formatting
WITH TEST_XML_EXTRACT AS
(
SELECT XMLTYPE (
'<tns:Envelope xmlns:tns="http://schemas.xmlsoap.org/soap/envelope/">
<testLeaf> ValueIWant </testLeaf>
</tns:Envelope>') testField
FROM dual
)
SELECT EXTRACTVALUE(testField,'/testLeaf'), -- doesn't work
EXTRACTVALUE(testField,'/tns'), -- doesn't work
EXTRACTVALUE(testField,'/Envelope'), -- doesn't work
EXTRACTVALUE(testField,'/BIPIBITY') -- doesn't work
FROM TEST_XML_EXTRACT;
It just returns blank.
And I can't find any exactly similar examples from the Oracle docs.
Any thoughts?
Upvotes: 1
Views: 120
Reputation: 35401
You might do better passing the namespace to the extract process
WITH TEST_XML_EXTRACT AS
( SELECT XMLTYPE (
'<tns:Envelope xmlns:tns="http://schemas.xmlsoap.org/soap/envelope/">
<testLeaf> ValueIWant </testLeaf>
</tns:Envelope>') testField
FROM dual)
select t.testField.extract('/tns:Envelope/testLeaf',
'xmlns:tns="http://schemas.xmlsoap.org/soap/envelope/"').getstringval() val,
EXTRACTVALUE(t.testField,'/tns:Envelope/testLeaf', 'xmlns:tns="http://schemas.xmlsoap.org/soap/envelope/"') extval,
EXTRACTVALUE(t.testField,'/*/testLeaf', 'xmlns:tns="http://schemas.xmlsoap.org/soap/envelope/"') extval_wc
from TEST_XML_EXTRACT t;
Upvotes: 1
Reputation: 65218
There's only testLeaf
node as a decently defined one in the XPath expression. So , only that could be extracted by using extractValue()
function in such a way below :
with test_xml_extract( testField ) as
(
select
XMLType(
'<tns:Envelope xmlns:tns="http://schemas.xmlsoap.org/soap/envelope/">
<testLeaf> ValueIWant </testLeaf>
</tns:Envelope>'
)
from dual
)
select extractValue(value(t), 'testLeaf') as testLeaf,
extractValue(value(t), 'tns') as tns,
extractValue(value(t), 'Envelope') as Envelope,
extractValue(value(t), 'BIPIBITY') as BIPIBITY
from test_xml_extract t,
table(XMLSequence(t.testField.extract('//testLeaf'))) t;
TESTLEAF TNS ENVELOPE BIPIBITY
---------- ------- ---------- ----------
ValueIWant
Upvotes: 1