English 中文(简体)
使用QXmlQuery(QtXQuery)时如何绑定命名空间前缀?
原标题:How does one bind namespace prefixes when using QXmlQuery (Qt XQuery)?
  • 时间:2011-02-16 01:25:08
  •  标签:
  • c++
  • qt
  • xquery

我正试图使用QXmlQuery对具有声明的默认名称空间的文档执行XQuery表达式。

供讨论:

<?xml version="1.0" encoding="UTF-8"?>
<root xmlns="http://namespace.com/ns1">
    <node1 attr1="hi"/>
</root>

现在,我有以下内容要打开并查询该文档:

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

QXmlQuery query;
query.setFocus(&temp);

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

query.evaluateTo(&items);

在运行这个过程中,项目中永远不会有数据,因为文档是按名称命名的。当然,如果我删除默认的名称空间声明,项确实有正确的数据,但我没有这种奢侈。

我试着将查询更改为:“/prefix:root”,Qt发出如下警告:

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

所以命名空间绑定确实存在!但是在哪里?我看到了QXmlNamePool,但它没有赋值函数方法。我可以通过查询ala创建一个带有池的QXmlName:

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

但它并没有改变任何事情。我不知所措,我使用的其他工具包都有将前缀绑定到命名空间URI的简单方法。

最佳回答

我相信如果您将查询更改为

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

它应该返回数据。

希望这有帮助,问候

问题回答

暂无回答




相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签