Dear Sirs, It is driving me nuts. You see all the basex examples here on Debian, only have simple examples, with no NAMESPACES involved. However, http://gdata.youtube.com/feeds/api/playlists/1ADE82BB5C96D594?prettyprint=tr... is the kind of data I am trying to deal with. Yes, you could say just do $ sed '2s/.*/<feed>/' and strip the namespaces. Ha ha ha. Well I did. And then there is media:* how do I deal with that. sed s/:// ? So instead I tried to look up how do declare namespaces. But I could
never mind.
Here's my makefile
N=\ declare namespace atom='http://www.w3.org/2005/Atom%27;%5C declare namespace app='http://purl.org/atom/app#%27;%5C declare namespace media='http://search.yahoo.com/mrss/%27;%5C declare namespace openSearch='http://a9.com/-/spec/opensearchrss/1.0/%27;%5C declare namespace gd='http://schemas.google.com/g/2005%27;%5C declare namespace gml='http://www.opengis.net/gml%27;%5C declare namespace yt='http://gdata.youtube.com/schemas/2007%27;%5C declare namespace georss='http://www.georss.org/georss';
F=1ADE82BB5C96D594?prettyprint=true P=http://gdata.youtube.com/feeds/api/playlists/$F s1:;basex -Vc "OPEN input; XQUERY $N " strippedF:$F;sed '2s/.*/<feed>/' $? |basex -Vc "CREATE DB input /dev/stdin; XQUERY /" xm:$F;basex -Vc "OPEN input; XQUERY (: xmlns:atom='http://www.w3.org/2005/Atom':) /*:feed" 1m:$F;basex -c "OPEN input; XQUERY declare copy-namespaces no-preserve,inherit;//*[local-name()='thumbnail']"|sed q edwm:$F;basex -Vc "OPEN input; XQUERY declare default element namespace 'ccc';//*[local-name()='thumbnail']" wm:$F;basex -Vc "OPEN input; XQUERY /*[local-name()='feed']/*[local-name()='entry']" m:$F;basex -Vc "OPEN input; XQUERY data(/*:feed/*:entry/*:id)"|tr ' ' \n m1:$F;basex -Vc "OPEN input; XQUERY /*:feed" c:$F;basex -Vc "OPEN input; XQUERY data(//*:name)[1]" c1:$F;basex -Vc "OPEN input; XQUERY (//*:name)[1]" b:$F;basex -Vc "CREATE DB input $?; XQUERY /"
My question: is it possible to use basex reasonably here shedding it of all the namespace baggage that I can not deal with. Thanks.
Hi,
My question: is it possible to use basex reasonably here shedding it of all the namespace baggage that I can not deal with.
If you just want to get rid of all the namespaces and your scenario doesn't evolve around huge amounts of data you could use the following approach, which has been posted on our list some time ago:
*declare function local:strip-namespace($e as element()) as element() {* * element {QName((), local-name($e))} {* * for $child in $e/(@*,*)* * return* * if ($child instance of element())* * then local:strip-namespace($child)* * else $child* * }* *};* * * You could then f.i. replace the original node with the node returned by the function, or create a new database from the result, ... Note that all namespace declarations will be completely removed!
Cheers, Lukas
OK, thanks. It turns out I forgot to escape the # at app# in my makefile. So I am back in business. Now I am curious how to get rid of the namespaces in output. declare copy-namespaces no-preserve, inherit doesn't work.
$ basex -Vc "OPEN input; XQUERY declare copy-namespaces no-preserve, inherit; declare namespace atom='http://www.w3.org/2005/Atom'; declare namespace app='http://purl.org/atom/app#'; declare namespace media='http://search.yahoo.com/mrss/'; declare namespace openSearch='http://a9.com/-/spec/opensearchrss/1.0/'; declare namespace gd='http://schemas.google.com/g/2005'; declare namespace gml='http://www.opengis.net/gml'; declare namespace yt='http://gdata.youtube.com/schemas/2007'; declare namespace georss='http://www.georss.org/georss'; for $e in /atom:feed/atom:entry for $t in $e/media:group/media:thumbnail return $t" Database 'input' opened in 65.84 ms. <media:thumbnail xmlns="http://www.w3.org/2005/Atom" xmlns:app="http://purl.org/atom/app#" xmlns:media="http://search.yahoo.com/mrss/" xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/" xmlns:gd="http://schemas.google.com/g/2005" xmlns:gml="http://www.opengis.net/gml" xmlns:yt="http://gdata.youtube.com/schemas/2007" xmlns:georss="http://www.georss.org/georss" url="http://i.ytimg.com/vi/_eXJ2JEPKuc/0.jpg" height="360" width="480" time="00:01:48"/> ... How can I just get <media:thumbnail url="http://i.ytimg.com/vi/_eXJ2JEPKuc/0.jpg" height="360" width="480" time="00:01:48"/> Thanks.
Hi Jidanni,
if you're only interested in the thumbnails plus some dedicated attributes:
<thumbnail url="http://i.ytimg.com/vi/_eXJ2JEPKuc/0.jpg" height="360" width="480" time="00:01:48"/> <thumbnail url="http://i.ytimg.com/vi/_eXJ2JEPKuc/1.jpg" height="90" width="120" time="00:00:54"/> <thumbnail url="http://i.ytimg.com/vi/_eXJ2JEPKuc/2.jpg" height="90" width="120" time="00:01:48"/>
Then this might help:
declare namespace ...
for $e in doc('input')/atom:feed/atom:entry for $t in $e/media:group/media:thumbnail return element { $t/local-name() } { $t/(@url, @height, @width, @time) }
Kind regards, Alex
On 26.11.2011, at 10:59, jidanni@jidanni.org wrote:
OK, thanks. It turns out I forgot to escape the # at app# in my makefile. So I am back in business. Now I am curious how to get rid of the namespaces in output. declare copy-namespaces no-preserve, inherit doesn't work.
$ basex -Vc "OPEN input; XQUERY declare copy-namespaces no-preserve, inherit; declare namespace atom='http://www.w3.org/2005/Atom'; declare namespace app='http://purl.org/atom/app#'; declare namespace media='http://search.yahoo.com/mrss/'; declare namespace openSearch='http://a9.com/-/spec/opensearchrss/1.0/'; declare namespace gd='http://schemas.google.com/g/2005'; declare namespace gml='http://www.opengis.net/gml'; declare namespace yt='http://gdata.youtube.com/schemas/2007'; declare namespace georss='http://www.georss.org/georss'; for $e in /atom:feed/atom:entry for $t in $e/media:group/media:thumbnail return $t" Database 'input' opened in 65.84 ms. <media:thumbnail xmlns="http://www.w3.org/2005/Atom" xmlns:app="http://purl.org/atom/app#" xmlns:media="http://search.yahoo.com/mrss/" xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/" xmlns:gd="http://schemas.google.com/g/2005" xmlns:gml="http://www.opengis.net/gml" xmlns:yt="http://gdata.youtube.com/schemas/2007" xmlns:georss="http://www.georss.org/georss" url="http://i.ytimg.com/vi/_eXJ2JEPKuc/0.jpg" height="360" width="480" time="00:01:48"/> ... How can I just get <media:thumbnail url="http://i.ytimg.com/vi/_eXJ2JEPKuc/0.jpg" height="360" width="480" time="00:01:48"/> Thanks. _______________________________________________ BaseX-Talk mailing list BaseX-Talk@mailman.uni-konstanz.de https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk
Hi jidanni,
as Lukas already mentioned, the best (cleanest) way to get rid of namespaces is to use a recursive function. The following query should work out of the box. You can save in a file and pass it on as command-line argument to basex: ______________________
declare function local:strip-namespace($e) { element { QName((), local-name($e)) } { for $child in $e/(@*,*) return if ($child instance of element()) then local:strip-namespace($child) else $child } };
let $doc := doc('http://gdata.youtube.com/feeds/api/playlists/1ADE82BB5C96D594?prettyprint=tr...') return local:strip-namespace($doc/*)
Fyi, Alex has added some more issues you encountered to the GitHub list:
https://github.com/BaseXdb/basex/issues/
Best, Christian ___________________________
On Sat, Nov 26, 2011 at 11:26 AM, Alexander Holupirek alexander.holupirek@uni-konstanz.de wrote:
Hi Jidanni,
if you're only interested in the thumbnails plus some dedicated attributes:
<thumbnail url="http://i.ytimg.com/vi/_eXJ2JEPKuc/0.jpg" height="360" width="480" time="00:01:48"/> <thumbnail url="http://i.ytimg.com/vi/_eXJ2JEPKuc/1.jpg" height="90" width="120" time="00:00:54"/> <thumbnail url="http://i.ytimg.com/vi/_eXJ2JEPKuc/2.jpg" height="90" width="120" time="00:01:48"/>
Then this might help:
declare namespace ...
for $e in doc('input')/atom:feed/atom:entry for $t in $e/media:group/media:thumbnail return element { $t/local-name() } { $t/(@url, @height, @width, @time) }
Kind regards, Alex
On 26.11.2011, at 10:59, jidanni@jidanni.org wrote:
OK, thanks. It turns out I forgot to escape the # at app# in my makefile. So I am back in business. Now I am curious how to get rid of the namespaces in output. declare copy-namespaces no-preserve, inherit doesn't work.
$ basex -Vc "OPEN input; XQUERY declare copy-namespaces no-preserve, inherit; declare namespace atom='http://www.w3.org/2005/Atom'; declare namespace app='http://purl.org/atom/app#'; declare namespace media='http://search.yahoo.com/mrss/'; declare namespace openSearch='http://a9.com/-/spec/opensearchrss/1.0/'; declare namespace gd='http://schemas.google.com/g/2005'; declare namespace gml='http://www.opengis.net/gml'; declare namespace yt='http://gdata.youtube.com/schemas/2007'; declare namespace georss='http://www.georss.org/georss'; for $e in /atom:feed/atom:entry for $t in $e/media:group/media:thumbnail return $t" Database 'input' opened in 65.84 ms. <media:thumbnail xmlns="http://www.w3.org/2005/Atom" xmlns:app="http://purl.org/atom/app#" xmlns:media="http://search.yahoo.com/mrss/" xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/" xmlns:gd="http://schemas.google.com/g/2005" xmlns:gml="http://www.opengis.net/gml" xmlns:yt="http://gdata.youtube.com/schemas/2007" xmlns:georss="http://www.georss.org/georss" url="http://i.ytimg.com/vi/_eXJ2JEPKuc/0.jpg" height="360" width="480" time="00:01:48"/> ... How can I just get <media:thumbnail url="http://i.ytimg.com/vi/_eXJ2JEPKuc/0.jpg" height="360" width="480" time="00:01:48"/> Thanks. _______________________________________________ BaseX-Talk mailing list BaseX-Talk@mailman.uni-konstanz.de https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk
BaseX-Talk mailing list BaseX-Talk@mailman.uni-konstanz.de https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk
basex-talk@mailman.uni-konstanz.de