我正在尝试使用BaseX将新元素插入到xml文档中。
declare variable $part external;
insert nodes $part as first into db:open("PARTDB")/assembly[@name="ZB09010"]
Run Code Online (Sandbox Code Playgroud)
我正在使用BaseX GUI进行测试,并定义了$ part变量(通过单击$图标)。
如果我使用“本地”变量,例如
let $up := <Employee Name="Joe">
<Personal>
<SSN>666-66-1234</SSN>
</Personal>
<StaffInfo>
<Position>Doctor</Position>
<AccountableTo>Jeff</AccountableTo>
</StaffInfo>
</Employee>
return
insert node $up as last into doc('office')/Staff
Run Code Online (Sandbox Code Playgroud)
那么插入将正常工作,但是,使用外部变量,每个保留的xml字符都将转换为xml转义字符序列,例如:<变为&lt;
我已经通过使用函数xquery:eval($ part)来包装变量来使其成功工作,但是在我看来,这就像是黑客。
我应该使用xs:string以外的其他类型来阻止翻译吗?还是我需要与外部变量一起使用以防止转换的某些功能。我也尝试用CDATA包装$ part xml内容,但是xml仍然转换为转义字符。
让我们采用我能想到的最简单的xquery函数:
declare function local:identityFunction($v as xs:integer)
{
return ($v)
};
Run Code Online (Sandbox Code Playgroud)
我在哪里申报?
我正在尝试使用exists-db和basex,但是如果我在查询处理器窗口中编写它,它们会给我一些错误(尽管正常的xqueries工作).
例如,basex抱怨以下消息:"Expecting expression".
我们正在寻找一种报告应用程序,该应用程序报告存储在大量XML文件中的数据.~3,000,000个文件,大小从7KB到5MB(每个文件符合相同的模式).我猜大约有200GB的XML.我正在研究一些开源XML数据库(Sedna,BaseX和eXist-db),我不确定这些系统的扩展程度,我在这里阅读了这三个数据库的比较.这是我对可伸缩性的关注源自哪里.
关于我们想要做的事情的一些细节是:我们不会更改任何XML文件中的数据,并且每天都会添加新文件.由于我们关注报告查询性能对我们很重要,因此添加和索引新文件所需的时间对我们来说不是一个高优先级.
我想知道是否有人有类似规模使用这些系统的经验?我查看了BaseX 统计信息页面,看到了一些相当大的XML实例,但没有提到性能.
我们不需要开源产品,MarkLogic系统看起来很适合这个账单,但我很好奇开源产品做了些什么.
所以我想distint-nodes在for子句中插入函数(参见下面的内容).我正在使用BaseX来达到这个目的.
这是我的代码:
<autores>{
for $a in doc("libros.xml")//libro
return
<autor>
<nombre>{
for $b in $a/autor
return concat($b/nombre,' ',$b/apellido)
}
</nombre>
{
for $c in doc("libros.xml")//libro
where $c/autor = $a/autor
return $c/titulo
}
</autor>
}
</autores>
Run Code Online (Sandbox Code Playgroud)
我想在第一个中使用这个函数,所以它只返回一个<autor/>元素的唯一实例:
for $b in distinct-nodes($a/autor)
return concat($b/nombre,' ',$b/apellido)
Run Code Online (Sandbox Code Playgroud)
但我收到以下错误(BaseX查询信息):
错误:停在G:/ Pruebas XML/XML/xqueryLibros.xq,6/31:[XPST0017]未知函数:fn:distinct-nodes.
为什么这个功能存在时是未知的?有什么我想念的吗?
编辑:我的目的是获取元素的唯一实例,$a/autor其中$a/autor/nombre和$a/autor/apellidos文本值相同
<autores>
<autor>
<nombre>W. Stevens</nombre>
<titulo>TCP/IP Ilustrado</titulo>
<titulo>Programación Avanzada en el entorno Unix</titulo>
</autor>
<autor>
<nombre>W. Stevens</nombre>
<titulo>TCP/IP Ilustrado</titulo>
<titulo>Programación …Run Code Online (Sandbox Code Playgroud) 我试图通过使用mondial.sql数据库通过陆地边界从一个国家到另一个国家来寻找可以通过陆地到达的所有国家.它必须以递归方式完成,我发现一些在线功能,我认为这对于连接序列很有用,并且能够排除已经找到的国家.
问题是,即使被排除的国家似乎得到妥善处理,我最终也会陷入困境.所以我的想法是,我可能必须以某种方式定义一个基本案例,以便在找到所有可能的国家后使递归停止.如何使用XQuery实现这一目标?
(:functx.value-union and is-value-in-sequence were found at http://www.xqueryfunctions.com/xq/:)
declare namespace functx = "http://www.functx.com";
declare function functx:value-union
( $arg1 as xs:anyAtomicType* ,
$arg2 as xs:anyAtomicType* ) as xs:anyAtomicType* {
distinct-values(($arg1, $arg2))
};
declare function functx:is-value-in-sequence
( $value as xs:anyAtomicType? ,
$seq as xs:anyAtomicType* ) as xs:boolean {
$value = $seq
} ;
(:Recursive function for finding reachable countries:)
declare function local:findReachable($countries, $country, $reachedCountries) {
let $reachableCountries := $countries[@car_code = $country/border/@country]
for $c in $reachableCountries
where not(functx:is-value-in-sequence($c, $reachedCountries))
return functx:value-union($c, local:findReachable($countries, …Run Code Online (Sandbox Code Playgroud) I have an XML file that represents the syntax trees of all the sentences in a book:
<book>
<sentence>
<w class="pronoun" role="subject">
I
</w>
<wg type="verb phrase">
<w class="verb" role="verb">
like
</w>
<wg type="noun phrase" role="object">
<w class="adj">
green
</w>
<w class="noun">
eggs
</w>
</wg>
</wg>
</sentence>
<sentence>
...
</sentence>
...
</book>
Run Code Online (Sandbox Code Playgroud)
This example is fake, but the point is that the actual words (the <w> elements) are nested in unpredictable ways based on syntactic relationships.
What I'm trying to …
我正在尝试构建简单的XML数据库(在BaseX或eXist-db中),但我无法确定如何修改文档中的值:
内容很简单,因为测试:
<p>
<pl>
<id>6></id>
</pl>
</p>
Run Code Online (Sandbox Code Playgroud)
我正在尝试构建类似函数的东西,<pl>如果元素不存在则会插入元素,如果存在则替换它.但XQuery给了我麻烦:
当我尝试使用if-then-else逻辑时:
if (exists(/p/pl[id=6]/name)=false)
then insert node <name>thenname</name> into /p/pl[id=6]
else replace value of node /p/pl[id=6]/name with 'elsename'
Run Code Online (Sandbox Code Playgroud)
我收到错误Error: [XUDY0027] Replace target must not be empty.显然我很困惑,为什么在两种情况下评估else部分,因此错误.当我清空其他部分时:
if (exists(/p/pl[id=6]/name)=true)
then insert node <name>thenname</name> into /p/pl[id=6]
else <dummy/>
Run Code Online (Sandbox Code Playgroud)
然后我明白了Error: [XUST0001] If expression: no updating expression allowed.
当我尝试声明更新功能时,即使它报告错误:
declare namespace testa='test';
declare updating function testa:bid($a, $b)
{
if (exists(/p/pl[id=6]/name)=true)
then insert node <name>thenname</name> into /p/pl[id=6]
else <dummy/>
};
testa:bid(0,0)
Run Code Online (Sandbox Code Playgroud)
Error: …
第一次尝试使用 XPath/Xquery,在 BaseX 中,我有一个 opendata.gov 的集合/数据库,用于下面的停车场片段,
<?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>
Run Code Online (Sandbox Code Playgroud)
我想要做的是找到某个地方的位置,在这个例子中是“Nunnery Lane”,然后返回停车场参考,所以我尝试过(数据库称为 Car_park_data,里面有 8 个文档)
collection("Car_park_data")/CarParkDataImport/CarPark[Location="Nunnery Lane"]/CarParkRef
Run Code Online (Sandbox Code Playgroud)
然后试过花
for $x in collection("Car_park_data")/CarParkDataImport/CarPark
where $x/Location="Nunnery Lane"
order by $x/CarParkRef
return $x/CarParkRef
Run Code Online (Sandbox Code Playgroud)
两者都没有命中……第一个查询的完整细节(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 …Run Code Online (Sandbox Code Playgroud) 我认识到使用 BaseX 客户端执行的 ( insert/ delete)-XQueries 始终返回空字符串。我发现这非常令人困惑或不直观。
有没有办法找出查询是否“成功”,而无需再次查询数据库(并使用可能有错误的“传递”逻辑,例如“如果我删除了一个节点,则 XML 中必须有 'oldNodeCount-1' 节点”) ?
我一直在尝试查询包含超过1500000项的BaseX数据库.当我运行此查询
for $item in collection('coll')//item
return $item (: returns an xml element :)
Run Code Online (Sandbox Code Playgroud)
它在不到一秒的时间内执行.
但是当我尝试在xml中返回结果时,我得到一个"Out of main memory"错误.
<xml>{
for $item in collection('coll')//item
return $item
}</xml>
Run Code Online (Sandbox Code Playgroud)
这是让我想放弃本机xml db方法的东西(与其他数据库一样,例如eXistDB),所以如果任何人有任何信息这个问题,那将是非常有帮助的.
谢谢