0
votes

I am using the following xml document structure:

<feed>
  <entry>
     <title>Title 1</title>
  </entry>
  <entry>
     <title>Entry by Sony</title>
  </entry>
</feed>

I am iterating over all documents in the database whose document name starts with "feed" eg: feed_doc1, feed_doc2 etc. I am searching for documents which contain a given key word and trying to return the name of the document. I am using BaseX XML Database and I am using the following xquery:

for $doc_name in db:list()
 where fn:starts-with($doc_name, 'feed')
    return
      for $node in doc($doc_name)/feed/entry[.//text() contains text 'Sony']]
        return $doc_name

In short, my query should return the document names of all those documents which contain the key word 'Sony'.

I see the following error:

java.io.IOException: org.basex.query.item.FTxt cannot be cast to org.basex.query.item.QNm

I tried to google about this error but could not find sufficient help information. Can someone help?

Thanks, Sony

1
What happens if you try return string($doc_name) ? - Travis Webb

1 Answers

0
votes

org.basex.query.item.FTxt => is a text node fragment and org.basex.query.item.QNm => is a Qualified Name or QName() you most likely have to convert the QName to string

however

the Ftxt (or Full Text) => would be this expression .//text() contains text 'Sony'

the double slashes "allows steps to operate on any descendant of a node" which can be in-precise and the Xquery 1.1 functions aren't needed I would do this

doc($doc_name)/entry/title[contains(text(),'Sony')]