1
votes

I'm getting the XDMP-NOTANODE error when I try to run an XQuery in MarkLogic. When I loaded my xml documents I loaded meta data files with them. I'm a student and I don't have experience in XQuery.

error:

[1.0-ml] XDMP-NOTANODE: (err:XPTY0019) $article/article/front/article-meta/title-group/article-title -- xs:untypedAtomic("
") is not a node
Stack Trace

At line 3 column 77:
In xdmp:eval("(for $article in fn:distinct-values(/article/text())&#9;&#9;    &#1...", (), <options xmlns="xdmp:eval"><database>4206169969988859108</database>   <root>C:\mls-projects\pu...</options>)
$article := xs:untypedAtomic("&#10;")
1. (for $article in fn:distinct-values(/article/text()) 
2. 
3. return (fn:distinct-values($article/article/front/article-meta/title-group/article-title)
4. 
5. 

Code:

(
 for $article in fn:distinct-values(/article/text())         
 return (
  fn:distinct-values($article/article/front/article-meta/title-group/article-title/text())
 )      
)
3

3 Answers

3
votes

Every $article is bound to an atomic value (fn:distinct-values() returns a sequence of atomic values). Then you try to apply a path expression (using the / operator) on $article. Which is forbidden, as the path operator requires its LHS operator to be nodes.

I am afraid your code does not make sense enough for me to suggest you an actual solution. I can only pinpoint where the error is.

Furthermore, using text() at the end of a path is most of the time a bad idea. And if /article is a complex document, it is certainly not what you want. One of the text nodes you select (most likely the first one) is simply one single newline character.

What do you want to achieve?

0
votes

Your $article variable is bound to an atomic value, not a node() from the article document. You can only use an XPath axis on a node.

When you apply the function distinct-values() in the for statement, it returns simple string values, not the article document or nodes from it.

You can probably make things work by using the values in a predicate filter like this:

for $article-text in fn:distinct-values(/article/text())         
return
  fn:distinct-values(/article[text()=$article-text]/front/article-meta/title-group/article-title/text())

Note: The above XQuery should avoid the XDMP-NOTANODE error, but there are likely easier (and more efficient) solutions for achieving your goal. If you were to post a sample of your document and describe what you are trying to achieve, we could suggest alternatives.

0
votes

Bit of a wild guess, but you have two distinct-values in your code. That makes me think you want a unique list of articles, and then finally a unique list of article-title's. I would hope you already have unique articles in your database, unless you are explicitly attempting to de-duplicate them.

In case you just want the overall unique list of article titles, I would do something like:

distinct-values(
    for $article in collection()/article
    return
        $article/front/article-meta/title-group/article-title
)

HTH!