我的目的是获得一个XML文件(如下图所示)中所有唯一标题的计数.但是,我收到如下错误:
Uncaught DOMException: Document.evaluate: The expression is not a legal expression
找不到哪里出了问题.
<channel>
<item>
<title>Trans Researchers Want Google Scholar to Stop Deadnaming Them</title>
<link>https://www.wired.com/story/trans-researchers-want-google-scholar-to-stop-deadnaming-them/</link>
<description>The academic search engine’s policy on name changes is out of step with other search tools and publishers.</description>
<category>Business</category>
<thumbnail>https://media.wired.com/photos/630fe159567860ab6c66c667/master/pass/business-deadnames-google.jpg</thumbnail>
</item>
<item>
<title>Babylon Disrupted the UK’s Health System. Then It Left</title>
<link>https://www.wired.com/story/babylon-disrupted-uk-health-system-then-left/</link>
<description>The AI-powered online doctor app is ditching its controversial NHS contracts as it focuses on the US market.</description>
<category>Business</category>
<thumbnail>https://media.wired.com/photos/63042ca2f06d7dee6f53bbc6/master/pass/Babylon-Leaves-NHS-Business-1253255825.jpg</thumbnail>
</item>
</channel>
我的JavaScript代码如下所示:
function displayCount() {
// get the number of distinct titles using xquery
var xquery = "count(distinct-values(/channel/item/title))";
var count = xmlFile.evaluate(xquery, xmlFile, null, XPathResult.ANY_TYPE, null);
//document.getElementById("count").innerHTML = count.textContent;
console.log(count.numberValue);
}
错误的原因是什么?我如何更正它?