如何在xmltype标记中获取名称空间值?

时间:2014-11-06 18:56:28

标签: xml oracle11g xmltype

我在oracle 11g中使用XmlType,我有一个这样的标签:

**<ProprietaryId Namespace="CMA_ID">ad017f3a9736ce9d8cbbfc89955aa033 </ProprietaryId>**

我想知道如何获取&#34; NameSpace&#34;的信息。 ?

以下是我正在使用的代码:

SELECT extractvalue( value (sr),'*/ReleaseId/ProprietaryId' )as ProprietaryId
  FROM XML_TABLE X,
       table(xmlsequence (extract(dados, '*/ContainedReleaseList/Release' )))sr

但我只能获取标签的信息而不是名称空间。

1 个答案:

答案 0 :(得分:0)

您需要使用@来指定您需要其值的属性。

这是一个示例查询。

SQL> with x(y) as (
select '<?xml version="1.0" encoding="UTF-8"?>
<service_orders count="1">
      <ProprietaryId Namespace="CMA_ID">ad017f3a9736ce9d8cbbfc89955aa033 </ProprietaryId>
</service_orders>' from dual
)
select
    extractvalue(xmltype(y),'service_orders/ProprietaryId/@Namespace')  as ProprietaryNamespace
from
    x;

PROPRIETARYNAMESPACE
-----------------------
CMA_ID

但EXTRACTVALUE已被弃用。您可以使用XMLTABLE。

SQL> with x(y) as (
select '<?xml version="1.0" encoding="UTF-8"?>
<service_orders count="1">
      <ProprietaryId Namespace="CMA_ID">ad017f3a9736ce9d8cbbfc89955aa033 </ProprietaryId>
</service_orders>' from dual
)
select
    prop.ProprietaryNamespace
from
    x,
    xmltable('service_orders/ProprietaryId'
        passing xmltype(x.y)
        columns ProprietaryNamespace varchar2(20) path '@Namespace'
        ) prop;

PROPRIETARYNAMESPACE
--------------------
CMA_ID