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. |