0

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'
1
  • 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. Commented Nov 8, 2011 at 22:12

2 Answers 2

1

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);
Sign up to request clarification or add additional context in comments.

Comments

-1

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()");

6 Comments

I suspect Ranon had the right idea but suffered finger-trouble supplying the code.
Guess you're totally right. Must have missed the preview. Copy-pasting seems to be quiet difficult.
Thanks, Ranon and Mike! By doing what Ranon suggested, the compiling error went away. query.isValid() returns true. However, query.evaluateTo(&segments) return false (segments is a QStringList instance to hold the query result) and hence I get an empty query result. I double check my query and they should be correct. Any further suggestion on how to debug further. I tried using F5 to step into the evaluateTo() function but didn't succeed. Thanks again!
Please provide some well-formed XML snippet against which we can run the query. Add small fragments to your question, bigger could be posted on gist for example.
I posted my source code and the xml document to the following link. Would be appreciated if you can take a look. Thanks a lot! gist.github.com/1355120
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.