QXmlQuery 没有结果

发布于 2024-08-18 15:41:36 字数 827 浏览 4 评论 0原文

我对此感到非常沮丧...

使用这个简单的 xml:

<?xml version='1.0'?>
<root>
   <data>hello</data>
</root>

这段代码

QXmlQuery xquery;
xquery.setQuery( "doc('config.xml')//data" );

if( xquery.isValid() )
{
    QXmlResultItems itemResult;
 xquery.evaluateTo( &itemResult );
 QXmlItem item( itemResult.next() );
 while( !item.isNull() )
 {
  QVariant value = item.toAtomicValue();
  qDebug() << "One XML result!!!";
  item = itemResult.next();
 }
}

这段代码根本不会给我任何结果。 我检查了应用程序的执行路径与config.xml所在的位置相同。

官方文档对我帮助不大,而且互联网上似乎没有关于如何使用此类的详细信息的额外信息。

我有另一个程序可以成功从 xml 加载数据,并且代码与发布的代码完全相同。如果找不到 xml 文件,甚至会抛出错误(我当前的应用程序不会发生这种情况)。

当然,我正在配置 .pro 文件以使用 xmlpatterns:

QT += xmlpatterns

有任何线索吗?

I'm getting really fustrated with this...

With this simple xml:

<?xml version='1.0'?>
<root>
   <data>hello</data>
</root>

And this code

QXmlQuery xquery;
xquery.setQuery( "doc('config.xml')//data" );

if( xquery.isValid() )
{
    QXmlResultItems itemResult;
 xquery.evaluateTo( &itemResult );
 QXmlItem item( itemResult.next() );
 while( !item.isNull() )
 {
  QVariant value = item.toAtomicValue();
  qDebug() << "One XML result!!!";
  item = itemResult.next();
 }
}

This code simply doesn't throw me any results.
I've checked that the execute path of app is the same where the config.xml is located.

Official documentation doesn't help me very much and seems there's no extra info on internet about details on how to use this class.

I have another program that successfully loads data from an xml and the code is exactly like the posted one. Even throws me an error if xml file is not found (a thing that with my current app doesn't happens).

Of course I'm configuring the .pro file to use xmlpatterns:

QT += xmlpatterns

Any clue??

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

难以启齿的温柔 2024-08-25 15:41:36

我记得我也遇到了一些麻烦...无论如何,我发现我正在使用以下几行:

QFile SourceDocument;
SourceDocument.setFileName(rXmlFilePath);
...
Query.bindVariable("inputDocument", &SourceDocument);
QString FinalQuery("declare variable $inputDocument external;doc($inputDocument)//chapter");
Query.setQuery(FinalQuery);

我希望它会对您有所帮助!

I remember I had some trouble with it as well... Anyway, I've found that I was using the following lines :

QFile SourceDocument;
SourceDocument.setFileName(rXmlFilePath);
...
Query.bindVariable("inputDocument", &SourceDocument);
QString FinalQuery("declare variable $inputDocument external;doc($inputDocument)//chapter");
Query.setQuery(FinalQuery);

I hope it will help you a bit !

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文