第一次尝试在 BaseX 中使用 XPath/Xquery,我有一个 opendata.gov 的集合/数据库,用于下面的 parking 场片段,
<?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”,然后返回 parking 场引用,所以我尝试了(数据库称为 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,没有命中
谢谢你的帮助
最佳答案
通过添加考虑命名空间
declare default element namespace "http://www.transportdirect.info/carparking";
关于xml - BaseX 上的 Xpath/Xquery 没有返回任何结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29590044/
我正在学习如何使用Nokogiri,根据这段代码我遇到了一些问题:require'rubygems'require'mechanize'post_agent=WWW::Mechanize.newpost_page=post_agent.get('http://www.vbulletin.org/forum/showthread.php?t=230708')puts"\nabsolutepathwithtbodygivesnil"putspost_page.parser.xpath('/html/body/div/div/div/div/div/table/tbody/tr/td/div
我正在寻找执行以下操作的正确语法(在Perl、Shell或Ruby中):#variabletoaccessthedatalinesappendedasafileEND_OF_SCRIPT_MARKERrawdatastartshereanditcontinues. 最佳答案 Perl用__DATA__做这个:#!/usr/bin/perlusestrict;usewarnings;while(){print;}__DATA__Texttoprintgoeshere 关于ruby-如何将脚
我好像记得Lua有类似Ruby的method_missing的东西。还是我记错了? 最佳答案 表的metatable的__index和__newindex可以用于与Ruby的method_missing相同的效果。 关于ruby-难道Lua没有和Ruby的method_missing相媲美的东西吗?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/7732154/
为什么4.1%2返回0.0999999999999996?但是4.2%2==0.2。 最佳答案 参见此处:WhatEveryProgrammerShouldKnowAboutFloating-PointArithmetic实数是无限的。计算机使用的位数有限(今天是32位、64位)。因此计算机进行的浮点运算不能代表所有的实数。0.1是这些数字之一。请注意,这不是与Ruby相关的问题,而是与所有编程语言相关的问题,因为它来自计算机表示实数的方式。 关于ruby-为什么4.1%2使用Ruby返
我有一个对象has_many应呈现为xml的子对象。这不是问题。我的问题是我创建了一个Hash包含此数据,就像解析器需要它一样。但是rails自动将整个文件包含在.........我需要摆脱type="array"和我该如何处理?我没有在文档中找到任何内容。 最佳答案 我遇到了同样的问题;这是我的XML:我在用这个:entries.to_xml将散列数据转换为XML,但这会将条目的数据包装到中所以我修改了:entries.to_xml(root:"Contacts")但这仍然将转换后的XML包装在“联系人”中,将我的XML代码修改为
我有一个奇怪的问题:我在rvm上安装了rubyonrails。一切正常,我可以创建项目。但是在我输入“railsnew”时重新启动后,我有“程序'rails'当前未安装。”。SystemUbuntu12.04ruby-v"1.9.3p194"gemlistactionmailer(3.2.5)actionpack(3.2.5)activemodel(3.2.5)activerecord(3.2.5)activeresource(3.2.5)activesupport(3.2.5)arel(3.0.2)builder(3.0.0)bundler(1.1.4)coffee-rails(
我想在一个没有Sass引擎的类中使用Sass颜色函数。我已经在项目中使用了sassgem,所以我认为搭载会像以下一样简单:classRectangleincludeSass::Script::FunctionsdefcolorSass::Script::Color.new([0x82,0x39,0x06])enddefrender#hamlengineexecutedwithcontextofself#sothatwithintemlateicouldcall#%stop{offset:'0%',stop:{color:lighten(color)}}endend更新:参见上面的#re
我想设置一个默认日期,例如实际日期,我该如何设置?还有如何在组合框中设置默认值顺便问一下,date_field_tag和date_field之间有什么区别? 最佳答案 试试这个:将默认日期作为第二个参数传递。youcorrectlysetthedefaultvalueofcomboboxasshowninyourquestion. 关于ruby-on-rails-date_field_tag,如何设置默认日期?[rails上的ruby],我们在StackOverflow上找到一个类似的问
我将我的Rails应用程序部署到OpenShift,它运行良好,但我无法在生产服务器上运行“Rails控制台”。它给了我这个错误。我该如何解决这个问题?我尝试更新rubygems,但它也给出了权限被拒绝的错误,我也无法做到。railsc错误:Warning:You'reusingRubygems1.8.24withSpring.UpgradetoatleastRubygems2.1.0andrun`gempristine--all`forbetterstartupperformance./opt/rh/ruby193/root/usr/share/rubygems/rubygems
我试图在索引页中创建一个超链接,但它没有显示,也没有给出任何错误。这是我的index.html.erb代码。ListingarticlesTitleTextssss我检查了我的路线,我认为它们也没有问题。PrefixVerbURIPatternController#Actionwelcome_indexGET/welcome/index(.:format)welcome#indexarticlesGET/articles(.:format)articles#indexPOST/articles(.:format)articles#createnew_articleGET/article