开发者

How does one bind namespace prefixes when using QXmlQuery (Qt XQuery)?

I'm attempting to use QXmlQuery to execute an XQuery expression against a document with a declared default namespace.

For discussion:

<?xml version="1.0" encoding="UTF-8"?>
<root xmlns="http://namespace.com/ns1">
    <no开发者_JAVA百科de1 attr1="hi"/>
</root>

Now, I have the following to open and query against the document:

QFile temp("my.xml");
temp.open(QIODevice::ReadOnly | QIODevice::Text);

QXmlQuery query;
query.setFocus(&temp);

QXmlResultItems items;
query.setQuery("/root");

query.evaluateTo(&items);

In running this, 'items' never has data in it, since the document is namespaced. Of course, if I remove the default namespace declaration, 'items' does have the correct data, but I don't have that luxury.

I've tried changing the query to: "/prefix:root", and Qt barks a warning like:

No namespace binding exists for the prefix prefix in prefix:root

So namespace binding does exist! But where? I see QXmlNamePool, but it has no mutator methods. I can create a QXmlName with the pool from the query ala:

QXmlName name(query.namePool(), "prefix", "http://namespace.com/ns1");

But it doesn't change anything. I'm at a loss, other toolkits I have used have simple methods to bind prefixes to namespace URIs.


I believe if you would change your query to

...
QXmlResultItems items;
query.setQuery("declare default element namespace \"http://namespace.com/ns1\"; /root");
...

it should return the data.

hope this helps, regards

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜