0

I am trying to parse an XML file using the following query (used in a cursor function): enter image description here

The problem I am facing is that my XML file contains 2 Namespaces, something like this: enter image description here

I could work it out in case there is only one xmlns, by defining p_urn to be the value of the xmlns.

How I can achieve this with the extract function in the case I have 2 xmlns?

1
  • Please edit your question to show your raw data, query and expected result as formatted text, not images. Commented Feb 15, 2021 at 22:43

1 Answer 1

1

You could do this by skipping or wild-carding some or all of the elements:

-- with only p_urn_1 - wildcard inner default namespace
select extractvalue(value(p), '/*:Header/*:VersionInfo/*:Version/text()', p_urn_1) as version
from table (xmlsequence(extract(xmltype(pp_xml), '/Document/*:Header', p_urn_1))) p;

-- with only p_urn_2 - wildcard outer default namespace
select extractvalue(value(p), '/Header/VersionInfo/Version/text()', p_urn_2) as version
from table (xmlsequence(extract(xmltype(pp_xml), '/*:Document/Header', p_urn_2))) p;

-- with only p_urn_2 - skip outer element
select extractvalue(value(p), '/Header/VersionInfo/Version/text()', p_urn_2) as version
from table (xmlsequence(extract(xmltype(pp_xml), '//Header', p_urn_2))) p;

-- without either p_urn_1 or p_urn_2 - wildcard everything
select extractvalue(value(p), '/*:Header/*:VersionInfo/*:Version/text()') as version
from table (xmlsequence(extract(xmltype(pp_xml), '/*:Document/*:Header'))) p;

-- with both p_urn_1 and p_urn_2 - single wildcard (safe-ish)
select extractvalue(value(p), '/Header/VersionInfo/Version/text()', p_urn_2) as version
from table (xmlsequence(extract(xmltype(pp_xml), '/Document/*:Header', p_urn_1))) p;

db<>fiddle

But you are using several deprecated functions. You should look at XMLQuery and XMLTable, which allow multiple namespaces; though providing the namespaces dynamically isn't easy.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.