问题
Looking at the "id" field for a twitter database:
thufir@dur:~/flwor$
thufir@dur:~/flwor$ basex
BaseX 9.0.1 [Standalone]
Try 'help' to get more information.
>
> open twitter
Database 'twitter' was opened in 218.67 ms.
>
> xquery //id
<id type="number">1224165280068382720</id>
<id type="number">60919433</id>
<id type="number">1224160851797643264</id>
<id type="number">60919433</id>
..
<id type="number">14248074</id>
Query executed in 268.13 ms.
>
how would I get the same result from a FLWOR
statement?
thufir@dur:~/flwor$
thufir@dur:~/flwor$ cat id.xq
for $tweets in db:open("twitter")
let $tweet := $tweets
return <results>{$tweet}</results>
thufir@dur:~/flwor$
which wraps everything in <result>
tags, but still gives every node. How is just the "id" node selected? Trying variations on:
let $tweet := $tweets/id
without positive results. Perhaps because there's JSON
in the mix?
回答1:
snowflake id's:
thufir@dur:~/flwor/twitter$
thufir@dur:~/flwor/twitter$ basex tweetID.xq
<tweet>
<id__str>1224165280068382720</id__str>
</tweet>
<tweet>
<id__str>1224160851797643264</id__str>
</tweet>
<tweet>
<id__str>1224134565280862208</id__str>
</tweet>
<tweet>
<id__str>1224133755562086406</id__str>
</tweet>
<tweet>
<id__str>1224117426364846081</id__str>
</tweet>
<tweet>
<id__str>1224113562777419777</id__str>
</tweet>
<tweet>
<id__str>1224083010015956992</id__str>
</tweet>
<tweet>
<id__str>1224080221663645697</id__str>
</tweet>
<tweet>
<id__str>1224042214541496320</id__str>
</tweet>
<tweet>
<id__str>1224041056024645632</id__str>
</tweet>
<tweet>
<id__str>1224036122344534017</id__str>
</tweet>
<tweet>
<id__str>1224017759132143616</id__str>
</tweet>
<tweet>
<id__str>1224016596634603520</id__str>
</tweet>
<tweet>
<id__str>1224001430417297410</id__str>
</tweet>
<tweet>
<id__str>1223987662094249991</id__str>
</tweet>
<tweet>
<id__str>1224165280068382720</id__str>
</tweet>
<tweet>
<id__str>1224160851797643264</id__str>
</tweet>
<tweet>
<id__str>1224134565280862208</id__str>
</tweet>
<tweet>
<id__str>1224133755562086406</id__str>
</tweet>
<tweet>
<id__str>1224117426364846081</id__str>
</tweet>
<tweet>
<id__str>1224113562777419777</id__str>
</tweet>
<tweet>
<id__str>1224083010015956992</id__str>
</tweet>
<tweet>
<id__str>1224080221663645697</id__str>
</tweet>
<tweet>
<id__str>1224042214541496320</id__str>
</tweet>
<tweet>
<id__str>1224041056024645632</id__str>
</tweet>
<tweet>
<id__str>1224036122344534017</id__str>
</tweet>
<tweet>
<id__str>1224017759132143616</id__str>
</tweet>
<tweet>
<id__str>1224016596634603520</id__str>
</tweet>
<tweet>
<id__str>1224001430417297410</id__str>
</tweet>
<tweet>
<id__str>1223987662094249991</id__str>
</tweet>
<tweet>
<id__str>1224165280068382720</id__str>
</tweet>
<tweet>
<id__str>1224160851797643264</id__str>
</tweet>
<tweet>
<id__str>1224134565280862208</id__str>
</tweet>
<tweet>
<id__str>1224133755562086406</id__str>
</tweet>
<tweet>
<id__str>1224117426364846081</id__str>
</tweet>
<tweet>
<id__str>1224113562777419777</id__str>
</tweet>
<tweet>
<id__str>1224083010015956992</id__str>
</tweet>
<tweet>
<id__str>1224080221663645697</id__str>
</tweet>
<tweet>
<id__str>1224042214541496320</id__str>
</tweet>
<tweet>
<id__str>1224041056024645632</id__str>
</tweet>
<tweet>
<id__str>1224036122344534017</id__str>
</tweet>
<tweet>
<id__str>1224017759132143616</id__str>
</tweet>
<tweet>
<id__str>1224016596634603520</id__str>
</tweet>
<tweet>
<id__str>1224001430417297410</id__str>
</tweet>
<tweet>
<id__str>1223987662094249991</id__str>
</tweet>
<tweet>
<id__str>1224165280068382720</id__str>
</tweet>
<tweet>
<id__str>1224160851797643264</id__str>
</tweet>
<tweet>
<id__str>1224134565280862208</id__str>
</tweet>
<tweet>
<id__str>1224133755562086406</id__str>
</tweet>
<tweet>
<id__str>1224117426364846081</id__str>
</tweet>
<tweet>
<id__str>1224113562777419777</id__str>
</tweet>
<tweet>
<id__str>1224083010015956992</id__str>
</tweet>
<tweet>
<id__str>1224080221663645697</id__str>
</tweet>
<tweet>
<id__str>1224042214541496320</id__str>
</tweet>
<tweet>
<id__str>1224041056024645632</id__str>
</tweet>
<tweet>
<id__str>1224036122344534017</id__str>
</tweet>
<tweet>
<id__str>1224017759132143616</id__str>
</tweet>
<tweet>
<id__str>1224016596634603520</id__str>
</tweet>
<tweet>
<id__str>1224001430417297410</id__str>
</tweet>
<tweet>
<id__str>1223987662094249991</id__str>
</tweet>
<tweet>
<id__str>1224165280068382720</id__str>
</tweet>
<tweet>
<id__str>1224160851797643264</id__str>
</tweet>
<tweet>
<id__str>1224134565280862208</id__str>
</tweet>
<tweet>
<id__str>1224133755562086406</id__str>
</tweet>
<tweet>
<id__str>1224117426364846081</id__str>
</tweet>
<tweet>
<id__str>1224113562777419777</id__str>
</tweet>
<tweet>
<id__str>1224083010015956992</id__str>
</tweet>
<tweet>
<id__str>1224080221663645697</id__str>
</tweet>
<tweet>
<id__str>1224042214541496320</id__str>
</tweet>
<tweet>
<id__str>1224041056024645632</id__str>
</tweet>
<tweet>
<id__str>1224036122344534017</id__str>
</tweet>
<tweet>
<id__str>1224017759132143616</id__str>
</tweet>
<tweet>
<id__str>1224016596634603520</id__str>
</tweet>
<tweet>
<id__str>1224001430417297410</id__str>
</tweet>
<tweet>
<id__str>1223987662094249991</id__str>
</tweet>thufir@dur:~/flwor/twitter$
thufir@dur:~/flwor/twitter$
thufir@dur:~/flwor/twitter$ cat tweetID.xq
for $tweets in db:open("twitter")
return <tweet>{$tweets/json/id__str}</tweet>
thufir@dur:~/flwor/twitter$
thufir@dur:~/flwor/twitter$
The FLWOR
:
for $tweets in db:open("twitter")
return <tweet>{$tweets/json/id__str}</tweet>
来源:https://stackoverflow.com/questions/60050240/add-an-xpath-statement-to-a-flowr-to-select-id-nodes-from-twitter-database