run xpath from xquery against a database?
How do I run an xpath
query from within an xquery
script with the basex
GUI?
successful xpath
query of a database:
failed xquery
attempt:
The simplest possible xquery
code for this database:
thufir@dur:~/basex$
thufir@dur:~/basex$ cat db_list_items.xq
let $db := db:open("list")
return root()/descendant::li/a/text()
thufir@dur:~/basex$
Not quite sure how to return results above.
error log from the basex
GUI:
Error:
Stopped at /home/thufir/basex/db_list_items.xq, 4/12:
[XPDY0002] root(): no context value bound.
Compiling:
- pre-evaluate db:open(database[,path]) to document-node(): db:open("list") -> db:open-pre("list", 0)
- inline $db_0
- simplify gflwor
Optimized Query:
root()/descendant::li/a/text()
Query:
let $db := db:open("list") return root()/descendant::li/a/text()
Query plan:
<QueryPlan compiled="true" updating="false">
<CachedPath type="text()*">
<FnRoot name="root([node])" type="node()?"/>
<IterStep axis="descendant" test="li" type="element()*"/>
<IterStep axis="child" test="a" type="element()*"/>
<IterStep axis="child" test="text()" type="text()*"/>
</CachedPath>
</QueryPlan>
looking for simple query of this database using basex
.
xml xpath xml-parsing xquery basex
add a comment |
How do I run an xpath
query from within an xquery
script with the basex
GUI?
successful xpath
query of a database:
failed xquery
attempt:
The simplest possible xquery
code for this database:
thufir@dur:~/basex$
thufir@dur:~/basex$ cat db_list_items.xq
let $db := db:open("list")
return root()/descendant::li/a/text()
thufir@dur:~/basex$
Not quite sure how to return results above.
error log from the basex
GUI:
Error:
Stopped at /home/thufir/basex/db_list_items.xq, 4/12:
[XPDY0002] root(): no context value bound.
Compiling:
- pre-evaluate db:open(database[,path]) to document-node(): db:open("list") -> db:open-pre("list", 0)
- inline $db_0
- simplify gflwor
Optimized Query:
root()/descendant::li/a/text()
Query:
let $db := db:open("list") return root()/descendant::li/a/text()
Query plan:
<QueryPlan compiled="true" updating="false">
<CachedPath type="text()*">
<FnRoot name="root([node])" type="node()?"/>
<IterStep axis="descendant" test="li" type="element()*"/>
<IterStep axis="child" test="a" type="element()*"/>
<IterStep axis="child" test="text()" type="text()*"/>
</CachedPath>
</QueryPlan>
looking for simple query of this database using basex
.
xml xpath xml-parsing xquery basex
add a comment |
How do I run an xpath
query from within an xquery
script with the basex
GUI?
successful xpath
query of a database:
failed xquery
attempt:
The simplest possible xquery
code for this database:
thufir@dur:~/basex$
thufir@dur:~/basex$ cat db_list_items.xq
let $db := db:open("list")
return root()/descendant::li/a/text()
thufir@dur:~/basex$
Not quite sure how to return results above.
error log from the basex
GUI:
Error:
Stopped at /home/thufir/basex/db_list_items.xq, 4/12:
[XPDY0002] root(): no context value bound.
Compiling:
- pre-evaluate db:open(database[,path]) to document-node(): db:open("list") -> db:open-pre("list", 0)
- inline $db_0
- simplify gflwor
Optimized Query:
root()/descendant::li/a/text()
Query:
let $db := db:open("list") return root()/descendant::li/a/text()
Query plan:
<QueryPlan compiled="true" updating="false">
<CachedPath type="text()*">
<FnRoot name="root([node])" type="node()?"/>
<IterStep axis="descendant" test="li" type="element()*"/>
<IterStep axis="child" test="a" type="element()*"/>
<IterStep axis="child" test="text()" type="text()*"/>
</CachedPath>
</QueryPlan>
looking for simple query of this database using basex
.
xml xpath xml-parsing xquery basex
How do I run an xpath
query from within an xquery
script with the basex
GUI?
successful xpath
query of a database:
failed xquery
attempt:
The simplest possible xquery
code for this database:
thufir@dur:~/basex$
thufir@dur:~/basex$ cat db_list_items.xq
let $db := db:open("list")
return root()/descendant::li/a/text()
thufir@dur:~/basex$
Not quite sure how to return results above.
error log from the basex
GUI:
Error:
Stopped at /home/thufir/basex/db_list_items.xq, 4/12:
[XPDY0002] root(): no context value bound.
Compiling:
- pre-evaluate db:open(database[,path]) to document-node(): db:open("list") -> db:open-pre("list", 0)
- inline $db_0
- simplify gflwor
Optimized Query:
root()/descendant::li/a/text()
Query:
let $db := db:open("list") return root()/descendant::li/a/text()
Query plan:
<QueryPlan compiled="true" updating="false">
<CachedPath type="text()*">
<FnRoot name="root([node])" type="node()?"/>
<IterStep axis="descendant" test="li" type="element()*"/>
<IterStep axis="child" test="a" type="element()*"/>
<IterStep axis="child" test="text()" type="text()*"/>
</CachedPath>
</QueryPlan>
looking for simple query of this database using basex
.
xml xpath xml-parsing xquery basex
xml xpath xml-parsing xquery basex
asked Jan 1 at 13:14
ThufirThufir
3,1761771163
3,1761771163
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Just like navigating a filesystem (or any other tree based structure), we need to know our place within that structure, in order to be able to use path expressions:
/home/logname/documents/work #> cd todo
/home/logname/documents/work/todo #>
How did the command line interpreter know, where to find the todo directory? It knew this, because, by convention, it assumed the context for the cd
command to be the current directory, which is /home/logname/documents/work
, in this case.
When you load a document/database into BaseX, it does the same for XPath expressions and also XQuerys, as long the context is clear. If you, for example, place a single dot .
in the query editor, and then execute that query, it will give you back the whole document, since this is what .
stands for: the current context item. Here, BaseX knows this context from the convention, that it executes, by default, queries against the currently loaded document, just like a command line interpreter assumes the current directory as the current context. One could say, that by loading the document/database, you cd
'ed into the root of that document. So far so good...
As soon as you use XQuery, you are using a complete programming language, that allows for much more, than just querying single documents. You could query a whole bunch of documents within one script.
Take this (incomplete) code fragment:
let $db := db:open("list")
let $db2 := db:open("list2")
If you now place queries the way you did, where do they go? Are they using $db
as context or $db2
?
What you need to do is to tell the processor about this. This can be done several ways:
- in the prolog of your script:
declare context item := db:open("list");
(see also: BaseX documentation on this and, very important, read about the difference between "static context" and "dynamic context" here) to learn more about context, in general. - in the XPath expression itself:
let $db := db:open("list")
return $db/root()/descendant::li/a/text()
or, simplified:
let $db := db:open("list")
return $db//li/a/text()
or:
declare context item := db:open("list");
.//li/a/text()
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53995730%2frun-xpath-from-xquery-against-a-database%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Just like navigating a filesystem (or any other tree based structure), we need to know our place within that structure, in order to be able to use path expressions:
/home/logname/documents/work #> cd todo
/home/logname/documents/work/todo #>
How did the command line interpreter know, where to find the todo directory? It knew this, because, by convention, it assumed the context for the cd
command to be the current directory, which is /home/logname/documents/work
, in this case.
When you load a document/database into BaseX, it does the same for XPath expressions and also XQuerys, as long the context is clear. If you, for example, place a single dot .
in the query editor, and then execute that query, it will give you back the whole document, since this is what .
stands for: the current context item. Here, BaseX knows this context from the convention, that it executes, by default, queries against the currently loaded document, just like a command line interpreter assumes the current directory as the current context. One could say, that by loading the document/database, you cd
'ed into the root of that document. So far so good...
As soon as you use XQuery, you are using a complete programming language, that allows for much more, than just querying single documents. You could query a whole bunch of documents within one script.
Take this (incomplete) code fragment:
let $db := db:open("list")
let $db2 := db:open("list2")
If you now place queries the way you did, where do they go? Are they using $db
as context or $db2
?
What you need to do is to tell the processor about this. This can be done several ways:
- in the prolog of your script:
declare context item := db:open("list");
(see also: BaseX documentation on this and, very important, read about the difference between "static context" and "dynamic context" here) to learn more about context, in general. - in the XPath expression itself:
let $db := db:open("list")
return $db/root()/descendant::li/a/text()
or, simplified:
let $db := db:open("list")
return $db//li/a/text()
or:
declare context item := db:open("list");
.//li/a/text()
add a comment |
Just like navigating a filesystem (or any other tree based structure), we need to know our place within that structure, in order to be able to use path expressions:
/home/logname/documents/work #> cd todo
/home/logname/documents/work/todo #>
How did the command line interpreter know, where to find the todo directory? It knew this, because, by convention, it assumed the context for the cd
command to be the current directory, which is /home/logname/documents/work
, in this case.
When you load a document/database into BaseX, it does the same for XPath expressions and also XQuerys, as long the context is clear. If you, for example, place a single dot .
in the query editor, and then execute that query, it will give you back the whole document, since this is what .
stands for: the current context item. Here, BaseX knows this context from the convention, that it executes, by default, queries against the currently loaded document, just like a command line interpreter assumes the current directory as the current context. One could say, that by loading the document/database, you cd
'ed into the root of that document. So far so good...
As soon as you use XQuery, you are using a complete programming language, that allows for much more, than just querying single documents. You could query a whole bunch of documents within one script.
Take this (incomplete) code fragment:
let $db := db:open("list")
let $db2 := db:open("list2")
If you now place queries the way you did, where do they go? Are they using $db
as context or $db2
?
What you need to do is to tell the processor about this. This can be done several ways:
- in the prolog of your script:
declare context item := db:open("list");
(see also: BaseX documentation on this and, very important, read about the difference between "static context" and "dynamic context" here) to learn more about context, in general. - in the XPath expression itself:
let $db := db:open("list")
return $db/root()/descendant::li/a/text()
or, simplified:
let $db := db:open("list")
return $db//li/a/text()
or:
declare context item := db:open("list");
.//li/a/text()
add a comment |
Just like navigating a filesystem (or any other tree based structure), we need to know our place within that structure, in order to be able to use path expressions:
/home/logname/documents/work #> cd todo
/home/logname/documents/work/todo #>
How did the command line interpreter know, where to find the todo directory? It knew this, because, by convention, it assumed the context for the cd
command to be the current directory, which is /home/logname/documents/work
, in this case.
When you load a document/database into BaseX, it does the same for XPath expressions and also XQuerys, as long the context is clear. If you, for example, place a single dot .
in the query editor, and then execute that query, it will give you back the whole document, since this is what .
stands for: the current context item. Here, BaseX knows this context from the convention, that it executes, by default, queries against the currently loaded document, just like a command line interpreter assumes the current directory as the current context. One could say, that by loading the document/database, you cd
'ed into the root of that document. So far so good...
As soon as you use XQuery, you are using a complete programming language, that allows for much more, than just querying single documents. You could query a whole bunch of documents within one script.
Take this (incomplete) code fragment:
let $db := db:open("list")
let $db2 := db:open("list2")
If you now place queries the way you did, where do they go? Are they using $db
as context or $db2
?
What you need to do is to tell the processor about this. This can be done several ways:
- in the prolog of your script:
declare context item := db:open("list");
(see also: BaseX documentation on this and, very important, read about the difference between "static context" and "dynamic context" here) to learn more about context, in general. - in the XPath expression itself:
let $db := db:open("list")
return $db/root()/descendant::li/a/text()
or, simplified:
let $db := db:open("list")
return $db//li/a/text()
or:
declare context item := db:open("list");
.//li/a/text()
Just like navigating a filesystem (or any other tree based structure), we need to know our place within that structure, in order to be able to use path expressions:
/home/logname/documents/work #> cd todo
/home/logname/documents/work/todo #>
How did the command line interpreter know, where to find the todo directory? It knew this, because, by convention, it assumed the context for the cd
command to be the current directory, which is /home/logname/documents/work
, in this case.
When you load a document/database into BaseX, it does the same for XPath expressions and also XQuerys, as long the context is clear. If you, for example, place a single dot .
in the query editor, and then execute that query, it will give you back the whole document, since this is what .
stands for: the current context item. Here, BaseX knows this context from the convention, that it executes, by default, queries against the currently loaded document, just like a command line interpreter assumes the current directory as the current context. One could say, that by loading the document/database, you cd
'ed into the root of that document. So far so good...
As soon as you use XQuery, you are using a complete programming language, that allows for much more, than just querying single documents. You could query a whole bunch of documents within one script.
Take this (incomplete) code fragment:
let $db := db:open("list")
let $db2 := db:open("list2")
If you now place queries the way you did, where do they go? Are they using $db
as context or $db2
?
What you need to do is to tell the processor about this. This can be done several ways:
- in the prolog of your script:
declare context item := db:open("list");
(see also: BaseX documentation on this and, very important, read about the difference between "static context" and "dynamic context" here) to learn more about context, in general. - in the XPath expression itself:
let $db := db:open("list")
return $db/root()/descendant::li/a/text()
or, simplified:
let $db := db:open("list")
return $db//li/a/text()
or:
declare context item := db:open("list");
.//li/a/text()
answered Feb 15 at 17:01


amixamix
2118
2118
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53995730%2frun-xpath-from-xquery-against-a-database%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown