【问题标题】:XML parsing using xmlsequence extract function (PL/SQL)使用 xmlsequence 提取函数 (PL/SQL) 进行 XML 解析
【发布时间】:2021-05-18 19:41:25
【问题描述】:

我正在尝试使用以下查询(在游标函数中使用)解析 XML 文件:

我面临的问题是我的 XML 文件包含 2 个命名空间,如下所示:

如果只有一个 xmlns,我可以通过将 p_urn 定义为 xmlns 的值来解决这个问题。

在我有 2 个 xmlns 的情况下,如何使用提取功能实现这一点?

【问题讨论】:

  • 请编辑您的问题以将您的原始数据、查询和预期结果显示为格式化文本,而不是图像。

标签: xml oracle plsql namespaces


【解决方案1】:

您可以通过跳过或通配部分或全部元素来做到这一点:

-- 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

但是您使用了几个已弃用的功能。您应该查看允许多个名称空间的 XMLQuery 和 XMLTable;虽然动态提供命名空间并不容易。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-06-20
    • 1970-01-01
    • 2013-06-22
    • 1970-01-01
    • 2012-08-15
    • 2023-03-29
    • 1970-01-01
    • 2015-11-14
    相关资源
    最近更新 更多