Changes

Jump to navigation Jump to search
470 bytes added ,  18:39, 1 December 2023
m
Text replacement - "syntaxhighlight" to "pre"
After 15 years of continuous development, the first double-digit version of BaseX is about to see sees the light of day soon.
We have taken the version jump as an opportunity to perform some major refactorings of BaseX, both under the hood and on API and XQuery level. Before migrating your projects to the new version, some adjustments may be required, so please read this article carefully.
The notorious {{Code|CHOP}} option was removed to prevent conflicting behavior caused by earlier installations. It was replaced by a new {{Option|STRIPWS}} option, which defaults to {{Code|false}}. In addition, the new default of the [[Serialization|serialization parameter]] {{Code|indent}} is {{Code|no}}.
Please be warned that the new default can throw off existing applications. If you want to restore the old behavior, you should assign attach the following values lines in your [[Configuration|.basex configuration file]], or the {{Code|web.xml}} file of your [[Web Application]]:
<syntaxhighlight pre lang="xqueryphp"># Local OptionsSTRIPWS: = trueSERIALIZER= indent=yes</pre> …or add context parameters in the {{Code|web.xml}} file of your [[Web Application]]:  <pre lang='xquery'><context-param> <param-name>org.basex.stripws</param-name> <param-value>true</param-value></context-param><context-param> <param-name>org.basex.serializer</param-name> <param-value>indent=yes</param-value></context-param></syntaxhighlightpre>
In the GUI editor, a [[Shortcuts#Editor Shortcuts|shortcut]] and an icon were added to switch result indentation on and off.
In addition, databases may considerably increase in size, as whitespaces used for indenting an XML document will be interpreted and stored as additional text nodes. If your XML resources are structured and have no [[Full-Text#Mixed Content|mixed content]], it is advisable to enable whitespaces stripping when importing them to a database.
 
Note that {{Option|STRIPWS}} only applies to stored XML and not to XML constructed within XQuery source files. Within XQuery code, the standard {{Code|boundary-space}} setting applies. This defaults to {{Code|strip}}. To preserve XML whitespace in XQuery modules, add the following to the prolog:
<pre lang='xquery'>
declare boundary-space preserve;
<xml> </xml>
</pre>
==Value Resources==
The new feature can e.g. be used to store maps in a database:
<syntaxhighlight pre lang="'xquery"'>
db:put-value(
'factbook',
'cities'
)
</syntaxhighlightpre>
…and use them as index later on:
<syntaxhighlight pre lang="'xquery"'>
let $cities := db:get-value('factbook', 'cities')
for $country in ('Japan', 'Indonesia', 'Malaysia')
return $country || ': ' || string-join($cities?($country), ', ')
</syntaxhighlightpre>
==Backups==
Lock detection will be performed after the first step, and the code resulting from this step offers much more insight into which specific databases need to be locked. As a result, local locks can be applied to many more queries than before, and many queries can now run in parallel. An example:
<syntaxhighlight pre lang="'xquery"'>
declare variable $n external;
db:get('names-' || $n)
</syntaxhighlightpre>
After the query has been parsed, a user-specific value (e.g., {{Code|123}}) will be bound to {{Code|$n}}. The variable will be inlined by the compiler, and the argument of {{Function||db:get}} will be pre-evaluated to {{Code|names123}}. It is then easy for the lock detector to collect the name of the database that needs to read-locked before the query is eventually executed.
XQuery Update provides constructs to [[XQuery Update#Main-Memory Updates|update XML nodes in main memory]]. The data structures for in-memory representations of XML resources have been revised, such that updates can be performed orders of magnitudes faster than before. With BaseX 9.x, the following query runs for several minutes, whereas it can now be computed in a few seconds:
<syntaxhighlight pre lang="'xquery"'>
<xml>{
(1 to 1000000) ! <child/>
return insert node text { $pos } into $child
}
</syntaxhighlightpre>
==Key-Value Store==
; Store data:
<syntaxhighlight pre lang="'xquery"'>
let $email := map:merge(
for $address in db:get('addressbook')//address
)
return store:put('emails', $email)
</syntaxhighlightpre>
; Retrieve data:
<syntaxhighlight pre lang="'xquery"'>
let $name := 'Richard David James'
return store:get('email')($name)
</syntaxhighlightpre>
The store is persistent: Its contents are written to disk if BaseX is shut down, and retrieved again after a restart.
=HTTP Requests=
HTTP requests in BaseX take advantage of are now based on the new [https://openjdk.org/groups/net/httpclient/intro.html Java HTTP Client]. This client provides a better overall performance, uses internal connection pools and follows redirects across different protocols (http, https).
HTTP operations are, among others, performed by:
Results in the {{Code|rest}} namespace are now returned without prefix:
<syntaxhighlight pre lang="xml">
<!-- before -->
<rest:databases xmlns:rest="http://basex.org/rest"/>
<!-- now -->
<databases xmlns="http://basex.org/rest"/>
</syntaxhighlightpre>
When listing the resources of a database, {{Code|dir}} elements are returned for resources that are located in subdirectories. See [[REST]] for more details.
Bureaucrats, editor, reviewer, Administrators
13,554

edits

Navigation menu