I am trying to extract the value of a tag with a name space in Oracle 10g. My query is
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
and it returns null
The original xml is this (I had to label as htp as opposed to http to avoid links):
<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/"D0YEQH88eSp7I2A9XRZQEU8."'>
<entry gd:etag='W/"CUMNRH47eCp7I2A9XRZRGUo."'>
<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 & 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>
Why am I getting null? If I select just /feed/entry[1] it returns xml for everything within the entry tag.
Since you are getting a result when you use /feed/entry[1]
it seems that your default (Atom) namespace is automatically registered. The yt
namespace is registered as well, so it should work.
You get null when you extract the string value of /feed/entry[1]/yt:statistics
because the <yt:statistics>
element has no text content. It's an empty tag. But you can read its attributes:
/feed/entry[1]/yt:statistics/@viewCount
and
/feed/entry[1]/yt:statistics/@favoriteCount