funkmaster20th
funkmaster20th

Reputation: 69

Xpath/Xquery on BaseX bringing back no results

Trying to use XPath/Xquery for the first time, within BaseX and i have a collection/database of opendata.gov for carpark snippet below,

<?xml version="1.0" encoding="utf-8"?>
<CarParkDataImport xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"     xsi:schemaLocation="http://www.transportdirect.info/carparking B:/CODE/carparks/CarParking.xsd" xmlns="http://www.transportdirect.info/carparking">
<CarPark>
    <CarParkRef>3</CarParkRef>
    <CarParkName>Nunnery Lane</CarParkName>
    <Location>York</Location>
    <Address>Nunnery Lane--York--North Yorkshire</Address>
    <Postcode>YO23 1AA</Postcode>
</CarPark>

what i am trying to do is find where the location is a certain place, in this instance "Nunnery Lane" and then return the carpark reference so i tried (the db is called Car_park_data, and has 8 documents inside)

collection("Car_park_data")/CarParkDataImport/CarPark[Location="Nunnery Lane"]/CarParkRef

and then tried flowr

for $x in collection("Car_park_data")/CarParkDataImport/CarPark
where $x/Location="Nunnery Lane"
order by $x/CarParkRef
return $x/CarParkRef

both bring back no hits..the full details the first query is(the result bit of basex)

Compiling:
- pre-evaluating fn:collection("Car_park_data")
- adding text() step
- applying text index
Query:
collection("Car_park_data")/CarParkDataImport/CarPark[Location="Nunnery  Lane"]/CarParkRef
Optimized Query:
db:text("Car_park_data", "Nunnery  Lane")/parent::Location/parent::CarPark[parent::CarParkDataImport/parent::docume nt-node()]/CarParkRef
Result:
- Hit(s): 0 Items
- Updated: 0 Items
- Printed: 0 Bytes
- Read Locking: local [Car_park_data]
- Write Locking: none
Timing:
- Parsing: 1.33 ms
- Compiling: 0.54 ms
- Evaluating: 0.36 ms
- Printing: 0.28 ms
- Total Time: 2.52 ms
Query plan:
<QueryPlan>
<CachedPath>
 <ValueAccess data="Car_park_data" type="TEXT">
  <Str value="Nunnery Lane" type="xs:string"/>
 </ValueAccess>
 <IterStep axis="parent" test="Location"/>
  <IterStep axis="parent" test="CarPark">
  <CachedPath>
    <IterStep axis="parent" test="CarParkDataImport"/>
    <IterStep axis="parent" test="document-node()"/>
  </CachedPath>
   </IterStep>
   <IterStep axis="child" test="CarParkRef"/>
  </CachedPath>
</QueryPlan>

what am i doing wrong, As i said using basex, you can see that it its viable Xpat/Xquery, (i.e. basex reports no errors) but i am guessing something wrong in my Xquery?

if i do an "find" with BaseX for "Nunnery Lane" this is the results that come back

Query:
/descendant-or-self::*[text() contains text "Nunnery Lane"]
Result:
- Hit(s): 4 Items
- Updated: 0 Items
- Printed: 601 Bytes
- Read Locking: global
- Write Locking: global

so i then tried adding the contains text to my query, to the same avale, no hits

Thank you for any help

Upvotes: 4

Views: 1673

Answers (1)

Martin Honnen
Martin Honnen

Reputation: 167716

Take the namespace into account by adding

declare default element namespace "http://www.transportdirect.info/carparking";

see http://www.w3.org/TR/xquery/#id-default-namespace.

Upvotes: 7

Related Questions