本文整理汇总了C++中QXmlQuery::bindVariable方法的典型用法代码示例。如果您正苦于以下问题:C++ QXmlQuery::bindVariable方法的具体用法?C++ QXmlQuery::bindVariable怎么用?C++ QXmlQuery::bindVariable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QXmlQuery
的用法示例。
在下文中一共展示了QXmlQuery::bindVariable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: query
//! [0]
StationInformation::List StationQuery::query(const QString &name)
{
const QString stationIdQueryUrl = QString("doc(concat('http://wap.trafikanten.no/FromLink1.asp?fra=', $station))/wml/card/p/small/a[@title='Velg']/substring(@href,18)");
const QString stationNameQueryUrl = QString("doc(concat('http://wap.trafikanten.no/FromLink1.asp?fra=', $station))/wml/card/p/small/a[@title='Velg']/string()");
QStringList stationIds;
QStringList stationNames;
QXmlQuery query;
query.bindVariable("station", QVariant(QString::fromLatin1(QUrl::toPercentEncoding(name))));
query.setQuery(stationIdQueryUrl);
query.evaluateTo(&stationIds);
query.bindVariable("station", QVariant(QString::fromLatin1(QUrl::toPercentEncoding(name))));
query.setQuery(stationNameQueryUrl);
query.evaluateTo(&stationNames);
if (stationIds.count() != stationNames.count()) // something went wrong...
return StationInformation::List();
StationInformation::List information;
for (int i = 0; i < stationIds.count(); ++i)
information.append(StationInformation(stationIds.at(i), stationNames.at(i)));
return information;
}
示例2: getAnyValue
std::string parserxml::getAnyValue(std::string pNodeDirectionValue)
{
if( !_file.open(QIODevice::ReadOnly))
{
qDebug() << "No se pudo abrir el XML para lectura.";
}
else
{
QXmlQuery query;
query.bindVariable("document", &_file);
std::string stringdocument = "doc($document)";
std::string finalstring = std::string(stringdocument) + std::string(pNodeDirectionValue);
query.setQuery(QString::fromStdString(finalstring));
if(!query.isValid())
{
qDebug()<< "Xpath invalido.";
}
QString queryresult;
query.evaluateTo(&queryresult);
if (queryresult == "\n")
{
queryresult = "";
}
_file.close();
return queryresult.toStdString();
}
}
示例3: newStationsAvailable
void ShoutcastFetcher::newStationsAvailable(QIODevice * openInputDevice, const QString & keyWord)
{
// Using read() putting the content into a QBuffer to workaround
// some strange hang if passing IO device directly into
// QXmlQuery object.
QByteArray content = openInputDevice->read(maxSize);
QBuffer buf(&content);
buf.open(QIODevice::ReadOnly);
QXmlQuery q;
q.bindVariable("stations", &buf);
q.setQuery("for $i in doc($stations)/stationlist/station " \
"let $tunein := doc($stations)/stationlist/tunein/@base " \
"return (string($i/@name), string($i/@id), string($i/@br), string($i/@genre)," \
" string($i/@lc), string($i/@mt), string($i/@ct), string($tunein))");
QStringList strings;
q.evaluateTo(&strings);
m_keywordStationMapping[keyWord].clear();
ShoutcastStationList & sl = m_keywordStationMapping[keyWord];
for (QStringList::const_iterator iter = strings.constBegin(); iter != strings.constEnd(); iter += 8)
{
QString tuneIn = stationsURL + *(iter + 1);
ShoutcastStation s(*iter, (*(iter + 1)).toInt(), (*(iter + 2)).toInt(),
*(iter + 3), (*(iter + 4)).toInt(), *(iter + 5), *(iter + 6),
tuneIn);
sl.append(s);
}
emit newStationsAvailable(keyWord);
}
示例4: Parse
void AVRStudioXMLParser::Parse(QString configDirPath, Part *pPart)
{
QXmlQuery query;
QString result;
query.bindVariable("partName", QVariant(configDirPath));
query.setQuery(GetXQuery());
query.evaluateTo(&result);
// for future use
QString errorMsg;
int line;
int col;
QDomDocument doc;
if(!doc.setContent(result, &errorMsg, &line, &col))
return;
QDomNode root = doc.firstChild();
QDomNode fuses = root.firstChild();
QDomNode locks = fuses.nextSibling();
QDomNode interfaces = locks.nextSibling();
pPart->SetFuseBits(GetBits(fuses.firstChild()));
pPart->SetLockBits(GetBits(locks.firstChild()));
pPart->SetProgrammingInterfaces(GetInterfaces(interfaces.firstChild()));
}
示例5: evaluate
void QueryMainWindow::evaluate(const QString &str)
{
/* This function takes the input string and displays the
* appropriate output using QXmlQuery.
*/
QXmlQuery query;
QFile sourceDocument;
sourceDocument.setFileName(":/files/cookbook.xml");
sourceDocument.open(QIODevice::ReadOnly);
query.bindVariable("inputDocument", &sourceDocument);
query.setQuery(str);
if(!query.isValid())
return;
QByteArray outArray;
QBuffer buffer(&outArray);
buffer.open(QIODevice::ReadWrite);
QXmlFormatter formatter(query, &buffer);
if(!query.evaluateTo(&formatter))
return;
buffer.close();
qFindChild<QTextEdit*>(this, "outputTextEdit")->setPlainText(QString::fromUtf8(outArray.constData()));
}
示例6: getQueueRequestCompleted
void NetFlixQueueProxy::getQueueRequestCompleted(int retCode, QString body){
qDebug() << "queue request completed!!";
qDebug() << retCode;
QXmlQuery query;
QString result;
QBuffer device;
device.setData(body.toUtf8());
device.open(QIODevice::ReadOnly);
query.bindVariable("netflix_queue",&device);
query.setQuery(QUrl("qrc:/queries/queue.xq"));
if (query.isValid())
{
if (query.evaluateTo(&result))
qDebug() << result;
else
qDebug() << "Evaluate failed";
}
else
qDebug() << "setQuery Failed.";
}
示例7: commandForPlayer
QString Server::commandForPlayer(QString aPlayerName)
{
mCommands->reset();
QXmlQuery* xmlQuery = new QXmlQuery;
xmlQuery->bindVariable(KXmlFileName,mCommands);
xmlQuery->bindVariable(KPlayer,QVariant(aPlayerName));
xmlQuery->setQuery(KXqReadCommandForPlayer);
QString result = QString();
if(xmlQuery->isValid())
{
xmlQuery->evaluateTo(&result);
}
delete xmlQuery;
return result;
}
示例8: render
void RssFeedNode::render(Grantlee::OutputStream* stream, Grantlee::Context* c)
{
QNetworkAccessManager *mgr = new QNetworkAccessManager(this);
QUrl url(Grantlee::getSafeString(m_url.resolve(c)));
QNetworkReply *reply = mgr->get(QNetworkRequest(url));
QEventLoop eLoop;
connect( mgr, SIGNAL( finished( QNetworkReply * ) ), &eLoop, SLOT( quit() ) );
eLoop.exec( QEventLoop::ExcludeUserInputEvents );
c->push();
foreach(Grantlee::Node *n, m_childNodes) {
if (!n->inherits(XmlNamespaceNode::staticMetaObject.className()))
continue;
Grantlee::OutputStream _dummy;
n->render(&_dummy, c);
}
QXmlQuery query;
QByteArray ba = reply->readAll();
QBuffer buffer;
buffer.setData(ba);
buffer.open(QIODevice::ReadOnly);
query.bindVariable("inputDocument", &buffer);
QString ns;
QHash<QString, QVariant> h = c->lookup("_ns").toHash();
QHash<QString, QVariant>::const_iterator it = h.constBegin();
const QHash<QString, QVariant>::const_iterator end = h.constEnd();
for ( ; it != end; ++it ) {
if (it.key().isEmpty()) {
ns += QLatin1Literal( "declare default element namespace " ) + QLatin1Literal( " \"" ) + it.value().toString() + QLatin1Literal( "\";\n" );
} else {
ns += QLatin1Literal( "declare namespace " ) + it.key() + QLatin1Literal( " = \"" ) + it.value().toString() + QLatin1Literal( "\";\n" );
}
}
query.setQuery(ns + "doc($inputDocument)" + Grantlee::getSafeString(m_query.resolve(c)).get());
QXmlResultItems result;
query.evaluateTo(&result);
QXmlItem item(result.next());
int count = 0;
while (!item.isNull()) {
if (count++ > 20)
break;
query.setFocus(item);
c->push();
foreach(Grantlee::Node *n, m_childNodes) {
if (n->inherits(XmlNamespaceNode::staticMetaObject.className()))
continue;
c->insert("_q", QVariant::fromValue(query));
n->render(stream, c);
}
c->pop();
item = result.next();
}
c->pop();
}
示例9: initFeedEntryList
void FeedEntryListModel::initFeedEntryList()
{
QFile queryFile(":/cxReader/xquery/feedEntryList.xq");
queryFile.open(QIODevice::ReadOnly);
QXmlQuery query;
query.setNetworkAccessManager(this->config->manager());
query.bindVariable("file", QVariant(this->config->baseUrl() + "/feeds/"+this->id));
query.setQuery(&queryFile);
this->namePool = query.namePool();
query.evaluateTo(this);
queryFile.close();
}
示例10: executeXmlQuery
QStringList ExternalPlaylist::executeXmlQuery(const QString& libraryPath, const QString& xPath, const QStringList& parameters){
QStringList results;
QFile xmlFile(libraryPath);
if (!xmlFile.open(QIODevice::ReadOnly))
return results;
QXmlQuery xmlQuery;
xmlQuery.bindVariable("inputDocument", &xmlFile);
// bind any other parameters
for(int i=0; i<(signed)parameters.size(); i += 2){
if(i + 1 >= (signed)parameters.size())
break;
xmlQuery.bindVariable(parameters[i], QVariant(parameters[i+1]));
}
xmlQuery.setQuery(xPath);
xmlQuery.evaluateTo(&results);
xmlFile.close();
return results;
}
示例11: genresAvailable
void ShoutcastFetcher::genresAvailable(QIODevice * openInputDevice)
{
// Using read() putting the content into a QBuffer to workaround
// some strange hang if passing IO device directly into
// QXmlQuery object.
m_genres.clear();
QByteArray content = openInputDevice->read(maxSize);
QBuffer buf(&content);
buf.open(QIODevice::ReadOnly);
QXmlQuery q;
q.bindVariable("glist", &buf);
q.setQuery("for $i in doc($glist)/genrelist/genre/@name return string($i)");
m_success = q.evaluateTo(&m_genres);
emit genresAvailable();
}
示例12: main
// Program entry point
int main(int argc, char **argv)
{
// Validate arguments
if (argc < 3) {
qFatal("Usage: %s <html-file> <xquery-file>\nUse - to read from stdin", argv[0]);
}
if (!strcmp(argv[1], "-") && !strcmp(argv[2], "-")) {
qFatal("Err, cannot read both HTML and XQuery file from stdin");
}
// We'll need a QCoreApplication instance for this
QCoreApplication app(argc, argv);
// Setup query first, so we can use its name pool
QXmlQuery query;
// Read HTML data
QFile htmlFile;
if (!openFile(&htmlFile, argv[1])) {
qFatal("Err, can't open HTML file %s", argv[1]);
}
QByteArray source = htmlFile.readAll();
QHtmlNodeModel model(query.namePool(), source, QUrl::fromLocalFile(argv[1]));
// Bind the "dom" variable to the root element of the document
query.bindVariable("dom", model.dom());
// Setup the query
QFile queryFile;
if (!openFile(&queryFile, argv[2])) {
qFatal("Err, can't open XQuery file %s", argv[2]);
}
query.setQuery(&queryFile, QUrl::fromLocalFile(argv[2]));
// Setup a formatter printing to stdout
QFile out;
out.open(stdout, QIODevice::WriteOnly);
QXmlFormatter formatter(query, &out);
// Evaluate and exit
if (!query.evaluateTo(&formatter)) {
return 1;
}
return 0;
}
示例13: handleMessage
void ErrorHandler::handleMessage(QtMsgType type,
const QString &description,
const QUrl &identifier,
const QSourceLocation &)
{
/* Don't use pDebug() in this function, it results in infinite
* recursion. Talking from experience.. */
Message msg;
msg.setType(type);
msg.setIdentifier(identifier);
/* Let's remove all the XHTML markup. */
QBuffer buffer;
buffer.setData(description.toLatin1());
buffer.open(QIODevice::ReadOnly);
QXmlQuery query;
query.bindVariable(QLatin1String("desc"), &buffer);
query.setQuery(QLatin1String("string(doc($desc))"));
QStringList result;
const bool success = query.evaluateTo(&result);
if(!description.startsWith(QLatin1String("\"Test-suite harness error:")))
{
const QString msg(QString::fromLatin1("Invalid description: %1").arg(description));
QVERIFY2(success, qPrintable(msg));
if(!success)
QTextStream(stderr) << msg;
}
if(!result.isEmpty())
msg.setDescription(result.first());
m_messages.append(msg);
}
示例14: stationsResult
void Parser131500ComAu::parseStationsByName(QNetworkReply *networkReply)
{
StationsResultList result;
QRegExp regexp = QRegExp("<select name=\"(.*)\" id=\"from\" size=\"6\" class=\"multiple\">(.*)</select>");
regexp.setMinimal(true);
regexp.indexIn(networkReply->readAll());
QString element = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><html xmlns=\"http://www.w3.org/1999/xhtml\">\n<body>\n" + regexp.cap(0) + "\n</body>\n</html>\n";
QBuffer readBuffer;
readBuffer.setData(element.toAscii());
readBuffer.open(QIODevice::ReadOnly);
QXmlQuery query;
query.bindVariable("path", &readBuffer);
//Query for more than one result
query.setQuery("declare default element namespace \"http://www.w3.org/1999/xhtml\"; declare variable $path external; doc($path)/html/body/select/option/string()");
QStringList stationNames;
if (!query.evaluateTo(&stationNames))
{
qDebug() << "parser131500ComAu::getStationsByName - Query 1 Failed";
}
for (int i = 0; i < stationNames.count(); i++) {
//Remove unneeded stuff from the result
stationNames[i].replace(" (Location)", "");
StationsResultItem *item = new StationsResultItem();
item->setStationName(stationNames[i].trimmed());
result.appendItem(item);
}
emit stationsResult(&result);
}
示例15: parseSearchJourney
void ParserHafasXml::parseSearchJourney(QNetworkReply *networkReply)
{
lastJourneyResultList = new JourneyResultList();
journeyDetailInlineData.clear();
QBuffer readBuffer;
readBuffer.setData(networkReply->readAll());
readBuffer.open(QIODevice::ReadOnly);
QXmlQuery query;
query.bindVariable("path", &readBuffer);
query.setQuery("doc($path)/ResC/Err//@text/string()");
QStringList errorResult;
if (!query.evaluateTo(&errorResult))
{
qDebug() << "parserHafasXml::ErrorTest - Query Failed";
}
if (errorResult.count() > 0 ) {
emit errorOccured(errorResult.join("").trimmed());
qWarning()<<"ParserHafasXml::parseSearchJourneyPart2:"<<errorResult.join("");
return;
}
//Query for station infos
query.setQuery("doc($path)/ResC/ConRes/ConnectionList/Connection/@id/string()");
QStringList resultIds;
if (!query.evaluateTo(&resultIds))
{
qDebug() << "parserHafasXml::getJourneyData 2 - Query Failed";
}
if (resultIds.count() <= 0) {
emit journeyResult(lastJourneyResultList);
return;
}
for(int i = 0;i<resultIds.count(); i++) {
//qDebug()<<"Connection:"<<resultIds[i];
query.setQuery("doc($path)/ResC/ConRes/ConnectionList/Connection[@id='" + resultIds[i] + "']/Overview/Date/string()");
QStringList dateResult;
if (!query.evaluateTo(&dateResult))
{
qDebug() << "parserHafasXml::getJourneyData 3 - Query Failed";
}
query.setQuery("doc($path)/ResC/ConRes/ConnectionList/Connection[@id='" + resultIds[i] + "']/Overview/Transfers/string()");
QStringList transfersResult;
if (!query.evaluateTo(&transfersResult))
{
qDebug() << "parserHafasXml::getJourneyData 4 - Query Failed";
}
query.setQuery("doc($path)/ResC/ConRes/ConnectionList/Connection[@id='" + resultIds[i] + "']/Overview/Duration/Time/string()");
QStringList durationResult;
if (!query.evaluateTo(&durationResult))
{
qDebug() << "parserHafasXml::getJourneyData 5 - Query Failed";
}
query.setQuery("doc($path)/ResC/ConRes/ConnectionList/Connection[@id='" + resultIds[i] + "']/Overview/Products/Product/@cat/string()");
QStringList trainsResult;
if (!query.evaluateTo(&trainsResult))
{
qDebug() << "parserHafasXml::getJourneyData 6 - Query Failed";
}
query.setQuery("doc($path)/ResC/ConRes/ConnectionList/Connection[@id='" + resultIds[i] + "']/Overview/Departure/BasicStop/Station/@name/string()");
QStringList depResult;
if (!query.evaluateTo(&depResult))
{
qDebug() << "parserHafasXml::getJourneyData 7 - Query Failed";
}
query.setQuery("doc($path)/ResC/ConRes/ConnectionList/Connection[@id='" + resultIds[i] + "']/Overview/Arrival/BasicStop/Station/@name/string()");
QStringList arrResult;
if (!query.evaluateTo(&arrResult))
{
qDebug() << "parserHafasXml::getJourneyData 8 - Query Failed";
}
query.setQuery("doc($path)/ResC/ConRes/ConnectionList/Connection[@id='" + resultIds[i] + "']/Overview/Departure/BasicStop/Dep/Time/string()");
QStringList depTimeResult;
if (!query.evaluateTo(&depTimeResult))
{
qDebug() << "parserHafasXml::getJourneyData 9 - Query Failed";
}
query.setQuery("doc($path)/ResC/ConRes/ConnectionList/Connection[@id='" + resultIds[i] + "']/Overview/Departure/BasicStop/Dep/Platform/Text/string()");
QStringList depPlatResult;
if (!query.evaluateTo(&depPlatResult))
{
qDebug() << "parserHafasXml::getJourneyData 10 - Query Failed";
}
query.setQuery("doc($path)/ResC/ConRes/ConnectionList/Connection[@id='" + resultIds[i] + "']/Overview/Arrival/BasicStop/Arr/Time/string()");
QStringList arrTimeResult;
//.........这里部分代码省略.........