Hello there,
I just want to do a simple xpath expression but I can't get it works when I use this XML document
<?xml version="1.0" encoding='utf-8'?> <feed xmlns="http://example.org" xmlns:abc="http://abc.example.org"> <title>Projects</title> </feed>
The expression "exquery //title" does not return anything from the CLI once I open the database containing only that file.
But it works with this file
<?xml version="1.0" encoding='utf-8'?> <feed xmlns="http://example.org"> <title>Projects</title> </feed>
It looks like having both xmlns and xmlns:abc namespace attribute creates a problem. My real use case is atompub feed document which the 2 first lines looks like this:
<?xml version="1.0" encoding='utf-8'?> <feed xmlns="http://www.w3.org/2005/Atom" xmlns:app="http://www.w3.org/2007/app">
Any idea? I'm using a 7.2.2 snapshot, thanks.
Hi Philippe,
you still have to declare a default element namespace for XQuery (or XPath for that matter) to recognize the element you want to return:
declare default element namespace "http://example.org";
<feed xmlns="http://example.org" xmlns:abc="http://abc.example.org"> <title>Projects</title> </feed>/title
will work as expected.
I see that the solution is not obvious, but from the processors point of view: * the XML fragment has the http://example.org namespace * your path expressions don't.
I modified your example slightly to show an alternative way of doing this:
declare namespace a = "http://example.org"; declare namespace b = "http://abc.example.org";
<feed xmlns="http://example.org" xmlns:abc="http://abc.example.org"> <title abc:test="foo">Projects</title> </feed>/a:title[@b:test = "foo"]
Feel free to ask for more help when needed,
Michael
Am 24.05.2012 um 04:20 schrieb Philippe Rathé:
Hello there,
I just want to do a simple xpath expression but I can't get it works when I use this XML document
<?xml version="1.0" encoding='utf-8'?>
<feed xmlns="http://example.org" xmlns:abc="http://abc.example.org"> <title>Projects</title> </feed>
The expression "exquery //title" does not return anything from the CLI once I open the database containing only that file.
But it works with this file
<?xml version="1.0" encoding='utf-8'?>
<feed xmlns="http://example.org"> <title>Projects</title> </feed>
It looks like having both xmlns and xmlns:abc namespace attribute creates a problem. My real use case is atompub feed document which the 2 first lines looks like this:
<?xml version="1.0" encoding='utf-8'?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:app="http://www.w3.org/2007/app">
Any idea? I'm using a 7.2.2 snapshot, thanks. _______________________________________________ BaseX-Talk mailing list BaseX-Talk@mailman.uni-konstanz.de https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk
But it works with this file
<?xml version="1.0" encoding='utf-8'?>
<feed xmlns="http://example.org"> <title>Projects</title> </feed>
...indeed it shouldn't work, as Michael already pointed out. But you are lucky; this issue has recently been fixed due to a bug report from Andy Bunce, which means that it should work again with the latest snapshot.
Btw, if you know that there's only one namespace in your document, you may as well use the wildcard instead of fully writing down your namespace:
//*:feed
C.
Christian and Michael,
indeed I'm overwhelmed by those new technologies. I just overlooked XML namespace! Thanks for your help.
-- Philippe
On Thu, May 24, 2012 at 11:58 AM, Christian Grün christian.gruen@gmail.com wrote:
But it works with this file
<?xml version="1.0" encoding='utf-8'?>
<feed xmlns="http://example.org"> <title>Projects</title> </feed>
...indeed it shouldn't work, as Michael already pointed out. But you are lucky; this issue has recently been fixed due to a bug report from Andy Bunce, which means that it should work again with the latest snapshot.
Btw, if you know that there's only one namespace in your document, you may as well use the wildcard instead of fully writing down your namespace:
//*:feed
C.
Michael,
Do I really need to declare a default namespace or can I just use namespace everywhere in my code and it will be ok? Will declaring a default namespace impact my existing code such as everything which is not prefixed by namespace like function variable or function call?
Thanks, -- Philippe
On Thu, May 24, 2012 at 10:23 PM, Philippe Rathé prathe@gmail.com wrote:
Christian and Michael,
indeed I'm overwhelmed by those new technologies. I just overlooked XML namespace! Thanks for your help.
-- Philippe
On Thu, May 24, 2012 at 11:58 AM, Christian Grün christian.gruen@gmail.com wrote:
But it works with this file
<?xml version="1.0" encoding='utf-8'?>
<feed xmlns="http://example.org"> <title>Projects</title> </feed>
...indeed it shouldn't work, as Michael already pointed out. But you are lucky; this issue has recently been fixed due to a bug report from Andy Bunce, which means that it should work again with the latest snapshot.
Btw, if you know that there's only one namespace in your document, you may as well use the wildcard instead of fully writing down your namespace:
//*:feed
C.
Do I really need to declare a default namespace or can I just use namespace everywhere in my code and it will be ok?
Defining a default namespace is just one option; it's completely ok to declare namespace and attach them to prefixes. You may as well use the new XQuery 3.0 notation:
Q{http://my.namespace.org/optional/path%7Dmy-function() ...
Hth, C.
I've read on namespaces and tried a default namespace on element as Michael suggested
declare default element namespace "http://www.w3.org/2005/Atom";
But RESTXQ raise an error that I didn't have before I declared it:
[REXQ9999] Variable $category is not specified as argument.
In fact it seems to raise on the first function that use a variable in the annotation. The variable is really passed as an argument, but I suspect that the argument is in my default namespace and so it is not "seen" by RESTXQ.
This is the function that created the error:
declare %rest:path("/categories/{$category}") %rest:GET %rest:produces("application/atomcat+xml") %output:omit-xml-declaration("no") %output:media-type("application/atomcat+xml") function page:category($category as xs:string) {
Am I forgetting something? Thanks, -- Philippe
On Fri, May 25, 2012 at 9:04 AM, Christian Grün christian.gruen@gmail.com wrote:
Do I really need to declare a default namespace or can I just use namespace everywhere in my code and it will be ok?
Defining a default namespace is just one option; it's completely ok to declare namespace and attach them to prefixes. You may as well use the new XQuery 3.0 notation:
Q{http://my.namespace.org/optional/path%7Dmy-function() ...
Hth, C.
basex-talk@mailman.uni-konstanz.de