2014-10-18 14:03 GMT+02:00 Elvis Stansvik <elvst...@gmail.com>: > Hi folks, > > I'm considering using QtXmlPatterns, but I need to be able to restrict > queries to only accept XPath 2.0 expressions, not the full XQuery 1.0 > language. > > This seems impossible at the moment; QXmlQuery supports either XQuery10 or > XSLT20 as values for queryLanguage. However, the QueryLanguage enum has a > hidden value XPath20 for internal purposes. I took a quick look, and this > seems to be used internally when parsing of XPath 2.0 expressions in XSLT > 2.0. > > I'm hoping someone intimately familiar with the query code can answer: > Would it be possible/feasible to add third public mode to the query parser, > one in which only XPath 2.0 is accepted? Or is this too much work / out of > scope? > > I haven't looked too closely at the code, but XPath 2.0 is a subset of > XQuery 1.0, so my hope is that it would not be an insurmountable effort to > add this. But I may be wrong. Also, I suspect QtXmlPatterns might not be > actively worked on except for bugfixing? >
After some experimentation, I've found that it's perfectly possible to pass the (internal) QXmlQuery::XPath20 value as queryLanguage. E.g QXmlQuery query; query.setQuery("declare variable $foo external; doc('index.html')/html/body/p[1]"); will work (default language is XQuery, so the variable declaration is OK), and so will QXmlQuery query(QXmlQuery::XPath20); // Internal value! query.setQuery("doc('index.html')/html/body/p[1]"); since it is valid XPath 2.0 (I removed the variable declaration). And lastly QXmlQuery query(QXmlQuery::XPath20); // Internal value! query.setQuery("declare variable $foo external; doc('index.html')/html/body/p[1]"); will barf as expected (I added the variable declaration back in): Error XPST0003 in file:///home/estan/test/test, at line 1, column 1: A construct was encountered which is disallowed in the current language(XPath 2.0). since variable declarations are not allowed in XPath 2.0. So from a quick look, it seems that it will Just Work (tm). That said, it's of course relying on internal behavior. My question is now: Anyone familiar enough with the code to know if this is "safe"? Will this just work? If so, could we consider making the QXmlQuery::XPath20 QueryLanguage value public API? Regards, Elvis > Cheers, > Elvis >
_______________________________________________ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest