How does XPath deal with XML namespaces?

前端 未结 2 917
梦谈多话
梦谈多话 2020-11-21 04:26

How does XPath deal with XML namespaces?

If I use

/IntuitResponse/QueryResponse/Bill/Id

to parse the XML document

2条回答
  •  有刺的猬
    2020-11-21 04:58

    I use /*[name()='...'] in a google sheet to fetch some counts from Wikidata. I have a table like this

     thes    WD prop links   items
     NOM     P7749   3925    3789
     AAT     P1014   21157   20224
    

    and the formulas in cols links and items are

    =IMPORTXML("https://query.wikidata.org/sparql?query=SELECT(COUNT(*)as?c){?item wdt:"&$B14&"[]}","//*[name()='literal']")
    =IMPORTXML("https://query.wikidata.org/sparql?query=SELECT(COUNT(distinct?item)as?c){?item wdt:"&$B14&"[]}","//*[name()='literal']")
    

    respectively. The SPARQL query happens not to have any spaces...

    I saw name() used instead of local-name() in Xml Namespace breaking my xpath!, and for some reason //*:literal doesn't work.

提交回复
热议问题