dbTalk Databases Forums  

How to specify the default namespace for queries?

comp.databases.berkeley-db comp.databases.berkeley-db


Discuss How to specify the default namespace for queries? in the comp.databases.berkeley-db forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Lemon Tree
 
Posts: n/a

Default How to specify the default namespace for queries? - 03-14-2006 , 07:21 AM






I am using DBXml and I cannot figure out how to specify the default
namespace for queries.

I have created a container with several XML documents like this one:

<foo xmlns="http://www.bar.org"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.bar.org foo.xsd">
<bar>
...
</bar>
<bar>
...
</bar>
</foo>

By using the dbxml utility I can succesfully perform the following
operations:

dbxml> openContainer foo.dbxml
dbxml> cquery "/foo/bar"
0 objects returned for eager expression '/foo/bar'
dbxml> setNamespace "" "http://www.bar.org"
dbxml> cquery "/foo/bar"
59042 objects returned for eager expression '/foo/bar'

So, binding the "" prefix to the "http://www.bar.org" makes
"http://www.bar.org" the default namespace and it correctly returns me
all the <bar> elements in the <foo> one.

I tried to do the same in my Java application:

XmlQueryContext xqc = xmlManager.createQueryContext();
xqc.setNamespace("", "http://www.bar.org");
XmlQueryExpression qe =
xmlManager.prepare("collection(\"foo.dbxml\")/foo/bar", xqc);
XmlResults results = qe.execute(xqc);

But it returns 0 objects in the XmlResults collection.

What's wrong with this?
Why don't I get the 59402 objects dbxml correctly finds?

Thank you for your help.


Reply With Quote
  #2  
Old   
Ron
 
Posts: n/a

Default Re: How to specify the default namespace for queries? - 03-14-2006 , 09:45 AM






Hi,

You cannot set a default namespace using setNamespace(). You could try
passing the namespace in the query expression. Try something similar
to:

xmlManager.prepare('declare default element namespace
"http://www.bar.org"; collection(\"foo.dbxml\")/foo/bar"', xqc);


Ron


Reply With Quote
  #3  
Old   
Lemon Tree
 
Posts: n/a

Default Re: How to specify the default namespace for queries? - 03-14-2006 , 11:19 AM




Ron ha scritto:

Quote:
xmlManager.prepare('declare default element namespace
"http://www.bar.org"; collection(\"foo.dbxml\")/foo/bar"', xqc);

Thanks.
It works.



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.