我正在尝试使用QtXmlQuery
从XML中提取一些数据。我想把它放到QStringList
。我尝试以下方法:
QByteArray in = "this is where my xml lives";
QBuffer received;
received.setData(in);
received.open(QIODevice::ReadOnly);
QXmlQuery query;
query.bindVariable("data", &received);
query.setQuery(NAMESPACE //contains definition of the t namespace
"doc($data)//t:service/t:serviceID/text()");
QBuffer outb;
outb.open(QIODevice::ReadWrite);
QXmlSerializer s(query, &outb);
query.evaluateTo(&s);
qDebug() << "buffer" << outb.data(); //This works perfectly!
QStringList * queryResult = new QStringList();
query.evaluateTo(queryResult);
qDebug() << "string list" << *queryResult; //This gives me no output!
正如您所看到的,当我通过QBuffer
将输出发送到QXmlSerializer
时,一切正常......但当我尝试使用QStringList
时,我什么都没得到。< / p>
答案 0 :(得分:2)
尝试使用string()
代替text()
,它应该有效。