0
votes

I'm using the QXmlQuery class in Qt to do XQuery on a soap response. As the response contains two namespaces, I use the declare clauses (the second and the third lines in the code snippet below) to declare them first before using them in the Xpath expression.

QXmlQuery query;

declare namespace s = "http://www.w3.org/2003/05/soap-envelope";

declare namespace ms = "http://schemas.microsoft.com/sharepoint/soap/";

query.setQuery("doc($xmlDoc)/s:Envelope/s:Body/ms:GetListCollectionResponse/ms:GetListCollectionResult/ms:Lists/ms:List/string()");

However, I got the following errors when compiling the code. Does anybody know how to fix this?

src/QtHelloWorldMakeCommImpl.cpp:79: error: 'declare' was not declared in this scope
src/QtHelloWorldMakeCommImpl.cpp:79: error: expected ';' before 'namespace'
src/QtHelloWorldMakeCommImpl.cpp:80: error: expected ';' before 'namespace'
2
Not sure about QXmlQuery, but it looks like you would try to declare the namespaces outside the query. There must be some function like query.declareNamespace or similar. - Jens Erat

2 Answers

1
votes

The "declare" statement is an XQuery statement, but you use it directly in the C++ file - this can't work. I have no Qt install here, but the following should work

QString queryStr(
"declare namespace s = \"http://www.w3.org/2003/05/soap-envelope\";\n"
"declare namespace ms = \"http://schemas.microsoft.com/sharepoint/soap/\";\n"
"doc($xmlDoc)/s:Envelope/s:Body/ms:GetListCollectionResponse/ms:GetListCollectionResult/ms:Lists/ms:List/string()");

query.setQuery(queryStr);
-1
votes

Have a look at this answer on how to declare namespaces. You try to declare it in C++-Code where declare is no keyword neighter you declarated it.

This should work:

query.setQuery("declare namespace s = \"http://www.w3.org/2003/05/soap-envelope\"; declare namespace ms = \"http://schemas.microsoft.com/sharepoint/soap/\"; doc($xmlDoc)/s:Envelope/s:Body/ms:GetListCollectionResponse/ms:GetListCollectionResult/ms:Lists/ms:List/string()");