0

I am a (so far) happy user of BaseX for a few month, but when I wanted to use this tool Today I noticed that for some weird reason the Xpath expressions and Xquery stopped working.

Whatever I type as XPath or Xquery just always returns "0 results" empty result. Not sure if there is any setting that I've set by mistake, but queries are good. I could test them with the same document in other tools - they are selecting things correctly

What is weirder, is that when I type an Xpath it looks like the typeahead suggests correct tags that come next in the tree etc. All the visual-navigation views work correctly but XPath or XQuery just does not work at all.

Anybody had such a problem and maybe found what is causing it?

Thank you

mono

Monoist
  • 1
  • 2
  • Can you be a bit more specific? Are you trying to select nodes in an XQuery database or on the file system? And which version of BaseX is that? – Martin Honnen Oct 14 '22 at 20:28
  • Sure. It is BaseX 9.7.3 Running on Win10 Basically any query via XPath or Xquery won't work Let's say I have an xml file, I create a Database from it. Once database is created I try to do a simplest possible Xpath expression like /Rootnode/Nodebelow - result is always empty, regardless if I start with option Find active or XQuery active or just try to write a FLOWR expression - whatever I try result is always empty. This is weird as at the same time, visualisation and typeahead show that BaseX understands the structure of the XML, just seem not understand Xpath on it – Monoist Oct 14 '22 at 20:41
  • Also tried to open various XML files - it does not seem to be file related. It's more like something got "broken" (or activated) in BaseX, but I cannot find what it is.. Same file+same query with a differnt editor (say, xpath explorer for N++) - query works fine, so it is also not a problem with the query. Also BaseX worked fine few weeks ago. I did not install a new version etc. It is the same program, just not working. – Monoist Oct 14 '22 at 20:46
  • Do wild card expressions like `/*/*` find elements? – Martin Honnen Oct 14 '22 at 21:06
  • 1
    It's hard to diagnose queries that return no results, but it's even harder when we can't see a source document or a query that demonstrates the problem. The most common cause of such problems is that your query is getting the namespace context wrong. It's also possible that you're searching the wrong input document. Without more detail, we just can't tell. – Michael Kay Oct 15 '22 at 07:34
  • Yes @MichaelKay - it was the namespace problem. See Below – Monoist Oct 15 '22 at 19:19

1 Answers1

0

Thank you very much for your help. I have found it in the meantime. Just needed some sleep probably. So. Actually BaseX did not stop working. It was a coincidence related to the fact that I have just started working with different files.

I will not bore you with the description of trying different things, but here is what was throwing BaseX out of the way (which is weird but still)

The document that was not working started with this tag:

<VendorItems xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://RedouteFrance/CAT-EXT-INTG/Product/VendorItems/1.0" xsi:schemaLocation="http://RedouteFrance/CAT-EXT-INTG/Product/VendorItems/1.0 VendorItems_1.0.xsd">
  <VendorItem>
    <EAN>4004758705459</EAN>

... and down the road it just contained many VendorItem blocks

So for example, a query like this, should return me all EANs //EAN/text() But the result was always empty. However the same document opened in N++ with XPath plugin worked fine.

I have luckily found this old SO question and answer -> Querying XML files using BaseX

So, inspired by this I have just removed the contents of the tag so it looks like this:

<VendorItems>
  <VendorItem>
    <EAN>4004758705459</EAN>

And, like by magic, BaseX started finding things correctly when queried via Xpath or Xquery...

I still do not get fully why those namespaces declarations were harmful, but I am glad it works now.

Best mono

Monoist
  • 1
  • 2
  • Just search for "XPath default namespace" and you will find 2073 other people who have had this problem -- and that excludes the questions marked as duplicates. – Michael Kay Oct 16 '22 at 10:40
  • Hello @MichaelKay - , I did not know it is a problem with XPath default namespace - hence I could not use this as a search keyword. But anyway thanks for your comment. – Monoist Oct 19 '22 at 10:31
  • Indeed. Thousands of people fall into this elephant trap, and unless you know the trap exists, you won't know why you have a problem. The answer is education and training: if people spent a day reading about a technology before trying to use it, they wouldn't have to spend a day trying to work out why they've got a problem later. – Michael Kay Oct 19 '22 at 10:59