[Qt-interest] Why is using XmlPatterns so cumbersome?
Frans Englich
frans.englich at nokia.com
Fri Mar 26 13:50:33 CET 2010
On Thursday 25 March 2010 18:22:13 ext Jason H wrote:
> I was reading:
> http://qt.nokia.com/developer/qtquarterly/checking-the-weather-with-xquery
>
> And I have seen this time and time again, and it keeps me from using the
> XmlPatterns stuff. 1. All the examples/documentation seem to work with
> static files ("doc("somefile.xml")"). Nothing uses "live" data off the web,
> or a QString or QByteArray that I already have. The 2nd example in the
> documentation for QXmlQuery::bindVariable(const QXmlName, QIODevice) shows
> setQuery then bindVariable, but the comments later say the proper way is
> the bind then set like in the 1st example.
QXmlItem's constructor takes a QVariant, so you can bind using:
bindVariable ( const QXmlName & name, const QXmlItem & value )
> 2. XPath isn't ever covered.
The description for the XQuery class has the section "Running XPath
Expressions" which says: "The XPath language is a subset of the XQuery
language, so running an XPath expression is the same as running an XQuery
query. Pass the XPath expression to QXmlQuery using setQuery()."
We don't have documentation for these languages as such, because it's outside
the scope of Qt and would be too big of a task to add(along the same lines to
why we don't have documentation on the C++ language).
> 3. There is no way to search and replace in XML using XQuery/XPath.
Correct. And well-known problem. What you and many others want is update
support. With a very concise syntax, it allows you to modify documents. Feel
free to comment/vote on: http://bugreports.qt.nokia.com/browse/QTBUG-2224
> I was hoping to see an example that takes a QUrl, gets it from the web
> (local content is so 1990), and runs it through the XPath/XQuery stuff.
Here's an example:
doc("http://example.com/index.html")/select/foo/bar
> In .Net, this is done much more simply. There is one class that is the XML
> document, then there is a Navigator class that attaches to that document
> (or any node of a document), that allows XPath queries.
>
> In.Net:
> m_provideMsgNav = doc->CreateNavigator();
> m_provideNSMgr = gcnew XmlNamespaceManager( m_provideMsgNav->NameTable);
> nodes = m_provideMsgNav->Select("/Some/Xpath/Expression", m_provideNSMgr);
> while (nodes->MoveNext())
> {
> ... // I can edit nodes here
> }
>
> To put it in Qt terms I wish to have:
> QXmlNavigator nav (&doc);
> QList<QDomNode> list = nav.findNode("/Some/Xpath/Expression");
> foreach (QDomNode n, list)
> {
> ...// and I can edit nodes here.
> }
How about this:
QXmlQuery query;
query.setQuery("doc('http://example.com/my/selection')/Some/XPath/expression");
QXmlResultItems result;
query.evaluateTo(&result);
QXmlItem item(result.next());
while(!item.isNull()) {
// use item. Yes, only read only
}
But we indeed need update support.
Jason and everyone else, we need input from people who know what they're
doing, and have clear specific ideas about how they'd like the module to
evolve. So do feel free to open reports on the QtXmlPatterns component, and
be as specific as possible.
http://qt.nokia.com/developer/the-qt-contribution-model
Notice also that via the contribution model, you can get your own code into
Qt.
Peter and I are also available in the #qt-labs channel on FreeNode, as
p--hartmann and FransE.
Cheers,
Frans
More information about the Qt-interest-old
mailing list