Topic on Talk:Wikidata Query Service/User Manual/MWAPI

Text nodes in output

2
Mxn (talkcontribs)

Can this service handle output elements that contain text nodes? I'm struggling to get back any output for the pageviews property:

SELECT ?title ?wd ?pageviews WHERE {
  SERVICE wikibase:mwapi {
    bd:serviceParam wikibase:api "Generator" .
    bd:serviceParam wikibase:endpoint "en.wikipedia.org" .
    bd:serviceParam mwapi:titles "List of mountain peaks by prominence" .
    bd:serviceParam mwapi:generator "links" .
    bd:serviceParam mwapi:gplprop "ids|title|type" .
    bd:serviceParam mwapi:gpllimit "max" .
    bd:serviceParam mwapi:pvipmetric "pageviews" .
    bd:serviceParam mwapi:pvipdays "1" .
    bd:serviceParam wikibase:limit 50 .
    
    ?title wikibase:apiOutput mwapi:title.
    ?wd wikibase:apiOutputItem mwapi:item.
    ?pageviews wikibase:apiOutput "pageviews/pvip/text()".
  }
}

I've tried a variety of XPaths, even pageviews/pvip/@date, but the ?pageviews column always ends up empty.

Each item in the API response looks like this:

      <page _idx="220167" pageid="220167" ns="0" title="Aconcagua">
        <pageviews>
          <pvip date="2021-04-27" xml:space="preserve">1266</pvip>
        </pageviews>
      </page>
91.159.71.53 (talkcontribs)

This seems to work

SELECT ?title ?wd ?pageviews WHERE {
  SERVICE wikibase:mwapi {
    bd:serviceParam wikibase:api "Generator" .
    bd:serviceParam wikibase:endpoint "en.wikipedia.org" .
    bd:serviceParam mwapi:titles "List of mountain peaks by prominence" .
    bd:serviceParam mwapi:generator "links" .
    bd:serviceParam mwapi:gplprop "ids|title|type" .
    bd:serviceParam mwapi:gpllimit "max" .
    bd:serviceParam mwapi:prop "info|pageprops|pageviews" .
    bd:serviceParam mwapi:pvipdays "1" .
    bd:serviceParam wikibase:limit 50 .
    
    ?title wikibase:apiOutput mwapi:title.
    ?wd wikibase:apiOutputItem mwapi:item.
    ?pageviews wikibase:apiOutput "pageviews/pvip/text()".

   }
}
Reply to "Text nodes in output"