【问题标题】:Extract/extractValue for tags with a namespace具有命名空间的标签的提取/提取值
【发布时间】:2014-06-23 14:31:53
【问题描述】:

我正在尝试在 Oracle 10g 中提取具有名称空间的标记的值。我的查询是

select      extract(xmltype(xml_text),
            '/feed/entry[1]/yt:statistics',
            'xmlns:yt="http://gdata.youtube.com/schemas/2007"') title
from    edgecast_xml
where   load_date > sysdate-1

它返回null

原始的 xml 是这样的(我不得不标记为 htp 而不是 http 以避免链接):

<feed xmlns='htp://www.w3.org/2005/Atom' xmlns:media='htp://search.yahoo.com/mrss/' xmlns:openSearch='htp://a9.com/-/spec/opensearch/1.1/' xmlns:gd='htp://schemas.google.com/g/2005' xmlns:yt='http://gdata.youtube.com/schemas/2007' gd:etag='W/&quot;D0YEQH88eSp7I2A9XRZQEU8.&quot;'>
    <entry gd:etag='W/&quot;CUMNRH47eCp7I2A9XRZRGUo.&quot;'>
       <id>tag:youtube.com,2008:video:qXPtXPJLnJY</id>
       <updated>2014-06-17T02:51:35.000Z</updated>
       <category scheme='http://schemas.google.com/g/2005#kind' term='http://gdata.youtube.com/schemas/2007#video'/>
       <category scheme='http://gdata.youtube.com/schemas/2007/categories.cat' term='Nonprofit' label='Nonprofits &amp; Activism'/>
       <title>Rear Admiral Lee Addresses Restrictive Regulations on Religious Liberty</title>
       <gd:rating average='4.8343196' max='5' min='1' numRaters='5239' rel='http://schemas.google.com/g/2005#overall'/>
       <yt:statistics favoriteCount='0' viewCount='365565'/>
       <yt:rating numDislikes='217' numLikes='5022'/>
   </entry>
</feed>

为什么我得到空值?如果我只选择 /feed/entry[1] 它会为 entry 标签中的所有内容返回 xml。

【问题讨论】:

  • 该 XML 中没有 xmlns。为什么要使用命名空间?
  • 我错误地忘记包含提要标签

标签: xml oracle plsql extract extract-value


【解决方案1】:

由于您在使用/feed/entry[1] 时获得了结果,因此您的默认(Atom)命名空间似乎已自动注册。 yt 命名空间也已注册,因此它应该可以工作。

当您提取/feed/entry[1]/yt:statistics 的字符串值时,您会得到null,因为&lt;yt:statistics&gt; 元素没有文本内容。这是一个空标签。但是你可以阅读它的属性:

/feed/entry[1]/yt:statistics/@viewCount

/feed/entry[1]/yt:statistics/@favoriteCount

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-06
    • 1970-01-01
    相关资源
    最近更新 更多