第一次尝试使用XPath / Xquery,在BaseX中,我有一个openndata.gov的集合/数据库,用于下面的carpark片段,
<?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>
我想要做的是找到位置是某个地方的位置,在这个例子中是“Nunnery Lane”,然后返回停车场参考,所以我试过(db叫做Car_park_data,里面有8个文件)
collection("Car_park_data")/CarParkDataImport/CarPark[Location="Nunnery Lane"]/CarParkRef
然后尝试了flowr
for $x in collection("Car_park_data")/CarParkDataImport/CarPark
where $x/Location="Nunnery Lane"
order by $x/CarParkRef
return $x/CarParkRef
两者都没有回击......第一个查询的完整细节(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>
我做错了什么,正如我所说的使用basex,你可以看到它是可行的Xpat / Xquery,(即basex报告没有错误),但我猜我的Xquery有什么问题?
如果我使用BaseX为“Nunnery Lane”进行“查找”,这将是回来的结果
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
所以我尝试将包含文本添加到我的查询中,添加到相同的avale,没有命中
感谢您的帮助
答案 0 :(得分:4)
通过添加
来考虑名称空间declare default element namespace "http://www.transportdirect.info/carparking";