本文整理汇总了C++中QXmlQuery::isValid方法的典型用法代码示例。如果您正苦于以下问题:C++ QXmlQuery::isValid方法的具体用法?C++ QXmlQuery::isValid怎么用?C++ QXmlQuery::isValid使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QXmlQuery
的用法示例。
在下文中一共展示了QXmlQuery::isValid方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: xml
QString F520xmlserializer::query(F520Status *f520, QString day, QString month, SysError &sysErr) {
QXmlQuery query;
QString res;
QFile xml(f520->getXmlPath());
if ( ! xml.exists()) {
xml.setFileName(f520->getXmlPath());
if ( ! xml.exists()) {
sysErr = SysError(SysError::F520_CAN_NOT_OPEN_FILE, "F520 Rasource file not exist");
return "";
}
}
if (!xml.open(QIODevice::ReadOnly | QIODevice::Text)) {
sysErr = SysError(SysError::F520_RESOUCES_NOT_EXIST, "F520 can not open xml resource file");
return "";
}
QString queryStr = CARICO + "/" + DAYS + "/" + DAY + "[@" + DAY_VALUE + "='" + day + "'][@" + MONTH_VALUE + "='" + month + "']";
qDebug() << "F520xmlserializer::query: " << queryStr;
query.setFocus(&xml);
query.setQuery(queryStr);
if ( ! query.isValid()) {
qDebug() << "F520xmlserializer::query query not valid";
sysErr = SysError(SysError::F520_QUERY_ERROR, "F520 Query is invalid: " + queryStr);
return "";
}
query.evaluateTo(&res);
if (!(res.length() > 1)) {
queryStr = CARICO + "/" + DAYS + "/" + DAY + "[@" + NAME + "='" + DEFAULT_DAY + "']";
qDebug() << "F520xmlserializer::query: " << queryStr;
query.setQuery(queryStr);
if (!query.isValid()) {
qDebug() << "F520xmlserializer::query query not valid";
sysErr = SysError(SysError::F520_QUERY_ERROR, "F520 Query is invalid: " + queryStr);
return "";
}
query.evaluateTo(&res);
}
xml.close();
qDebug() << "F520xmlserializer::query " << res;
QDomDocument watt;
watt.setContent("" + res + "");
QDomNodeList entryNodes = watt.elementsByTagName(DAY);
QString rtn;
for (int i = 0; i < entryNodes.count(); i++) {
QDomElement node = entryNodes.at(i).toElement();
rtn = node.attribute(WATT);
break;
}
qDebug() << "F520xmlserializer::query " << rtn;
return rtn;
}
示例2: findElement
SimXmlElement SimXmlDoc::findElement(const std::string& elementName, const std::string& refId) const
{
SimXmlElement result(QSharedPointer<QDomElement>(), *this);
if (isNull()){
return result;
}
QString queryString = simQuery("/SimModel/" + elementName + "[@RefId='" + refId + "'][1]");
QXmlQuery query;
QDomNodeModel model(query.namePool(), *(impl()));
query.setFocus(QXmlItem(model.fromDomNode(impl()->documentElement())));
query.setQuery(queryString, QUrl(QString::fromStdString(this->path())));
if (query.isValid()) {
QXmlResultItems items;
query.evaluateTo(&items);
QXmlItem item(items.next());
if(!item.isNull()) {
QDomElement elem = model.toDomNode(item.toNodeModelIndex()).toElement();
QSharedPointer<QDomElement> impl(new QDomElement(elem));
result = SimXmlElement(impl, *this);
}
}
return result;
}
示例3: 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.";
}
示例4: 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()));
}
示例5: evaluate
void tst_QXmlResultItems::evaluate() const
{
QFETCH(QString, queryString);
QXmlQuery query;
query.setQuery(queryString);
QVERIFY(query.isValid());
QXmlResultItems result;
query.evaluateTo(&result);
QXmlItem item(result.next());
while(!item.isNull())
{
QVERIFY(!result.current().isNull());
QVERIFY(!result.hasError());
item = result.next();
}
/* Now, stress beyond the end. */
for(int i = 0; i < 3; ++i)
{
QVERIFY(result.current().isNull());
QVERIFY(result.next().isNull());
}
}
示例6: 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();
}
}
示例7: bindVariable
/*!
Binds the result of the query \a query, to a variable by name \a name.
Evaluation of \a query will be commenced when this function is called.
If \a query is invalid, behavior is undefined. \a query will be copied.
\since 4.5
\sa isValid()
*/
void QXmlQuery::bindVariable(const QXmlName &name, const QXmlQuery &query)
{
Q_ASSERT_X(query.isValid(), Q_FUNC_INFO, "The query being bound must be valid.");
const QPatternist::VariableLoader::Ptr vl(d->variableLoader());
const QVariant variant(QVariant::fromValue(query));
if(vl->invalidationRequired(name, variant))
d->recompileRequired();
vl->addBinding(name, variant);
}
示例8: 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;
}
示例9: runXmlQuerry
QString runXmlQuerry(QFile *file, QString querry)
{
F_TRACE;
QXmlQuery query;
QString res;
file->seek(0);
query.setFocus(file);
query.setQuery(querry);
if ( ! query.isValid())
{
qDebug() << "Invalid querry" << querry;
}
query.evaluateTo(&res);
return res.simplified();
}
示例10: serializationError
void tst_QXmlSerializer::serializationError() const
{
QFETCH(QString, queryString);
QXmlQuery query;
MessageSilencer silencer;
query.setMessageHandler(&silencer);
query.setQuery(queryString);
QByteArray output;
QBuffer buffer(&output);
QVERIFY(buffer.open(QIODevice::WriteOnly));
QVERIFY(query.isValid());
QXmlSerializer serializer(query, &buffer);
QEXPECT_FAIL("Two top elements", "Bug, this is not checked for", Continue);
QVERIFY(!query.evaluateTo(&serializer));
}
示例11: model
std::vector<SimXmlElement> SimXmlDoc::getElements(const std::string& elementName) const
{
std::vector<SimXmlElement> result;
if (isNull()){
return result;
}
QString queryString = simQuery("/SimModel/" + elementName);
QXmlQuery query;
QDomNodeModel model(query.namePool(), *(impl()));
query.setFocus(QXmlItem(model.fromDomNode(impl()->documentElement())));
query.setQuery(queryString, QUrl(QString::fromStdString(this->path())));
if (query.isValid()) {
QString junk;
QXmlResultItems items;
query.evaluateTo(&items);
QXmlItem item(items.next());
while (!item.isNull()) {
QDomElement elem = model.toDomNode(item.toNodeModelIndex()).toElement();
QSharedPointer<QDomElement> impl(new QDomElement(elem));
result.push_back(SimXmlElement(impl, *this));
// get next item
item = items.next();
}
}
return result;
}
示例12: parseSearchRequestData
bool SeLogerHousingDriver::parseSearchRequestData( const QByteArray& data, Announcement::List& announcements, RequestResultProperties* properties ) const
{
// before parsing the announce, we convert the xml to a standard simple one using xquery
const QString xpath = xPathQuery();
QXmlQuery query;
QString xml;
if ( !query.setFocus( QString::fromUtf8( data ) ) ) {
if ( properties ) {
properties->error = tr( "%s: Can't set focus" ).arg( Q_FUNC_INFO );
}
qWarning( "%s: 1", Q_FUNC_INFO );
return false;
}
query.setQuery( xpath, QUrl( d->webServiceUrl() ) );
if ( !query.isValid() ) {
if ( properties ) {
properties->error = tr( "%s: Invalid query" ).arg( Q_FUNC_INFO );
}
qWarning( "%s: 2", Q_FUNC_INFO );
return false;
}
if ( !query.evaluateTo( &xml ) ) {
if ( properties ) {
properties->error = tr( "%s: Can't evaluateTo" ).arg( Q_FUNC_INFO );
}
qWarning( "%s: 3", Q_FUNC_INFO );
return false;
}
return parseStandardDomDocument( xml, announcements, properties );
}
示例13: testXmlQuery
void TestSimulationMaker::testXmlQuery()
{
writeQuery("/simulation/model", 1);
writeQuery("/simulation//model[@type='LifeCycle']", 2);
writeQuery("/simulation/model[@name='wasp']/model[@name='egg']/parameter[@name='k']", 3);
writeQuery("/simulation/output[@name='butterflyOutput']/"
"presentation[@name='butterflyPlot']/xyvariables[@name='butterflyXY']", 4);
QXmlQuery query;
query.setQuery("<e/>, 1, 'two'");
QXmlResultItems result;
if (query.isValid()) {
query.evaluateTo(&result);
QXmlItem item(result.next());
while (!item.isNull()) {
// use item
item = result.next();
}
if (result.hasError())
/* Runtime error! */;
}
}
示例14: RetrieveOEB
bool qPBReaderEpub::RetrieveOEB(QStringList & olsOpf)
{
TRSCOPE(epub, "qPBReaderEpub::RetrieveOEB");
// try settings
bool b = _pSettings->GetOpf(olsOpf);
// or analyze container
if (b && !olsOpf.size())
{
TRACE << "Reading container" << endl;
// create query from file
QXmlQuery qry;
b = qry.setFocus(QUrl(_sTempDir + "/" CONTAINER));
TRACE << "qry.setFocus(...): " << b << endl;
// prepare query
// retrieve full-path from container/rootfiles/root elements where media-type=OEBPS_TYPE
if (b)
{
qry.setQuery("declare default element namespace \"" CONTAINERNS "\";"
"/container/rootfiles/rootfile[lower-case(@media-type)='" OEBPS_TYPE
"']/@full-path/string()");
b = qry.isValid();
TRACE << "qry.isValid(): " << b << endl;
}
// execute it
QStringList lsTmp;
if (b)
{
b = qry.evaluateTo(&lsTmp) && lsTmp.size() > 0;
TRACE << "evaluation " << b << " nbopf=" << lsTmp.size() << endl;
}
// get and make results persist
if (b)
{
_pSettings->SaveOpf(lsTmp);
olsOpf = lsTmp;
}
}
if (!b)
{
olsOpf.clear();
}
else if (TRACEON)
{
for (int idx = 0; idx < olsOpf.size(); idx++)
{
TRACE << ENC(olsOpf[idx]) << endl;
}
}
return b;
}
示例15: invoiceSelectData
InvoiceData XmlDataLayer::invoiceSelectData(QString name, int type) {
qDebug() << __FILE__ << __LINE__ << __FUNCTION__;
InvoiceData o_invData;
QDomDocument doc(sett().getInoiveDocName());
QDomElement root;
QDomElement nabywca;
QDomElement product;
QString fName = name;
QFile file(sett().getInvoicesDir() + fName);
if (!file.open(QIODevice::ReadOnly)) {
qDebug("file doesn't exist");
return o_invData;
} else {
QTextStream stream(&file);
if (!doc.setContent(stream.readAll())) {
file.close();
return o_invData;
}
}
root = doc.documentElement();
o_invData.frNr = root.attribute("no");
o_invData.sellingDate = QDate::fromString(root.attribute("sellingDate"), sett().getDateFormat());
o_invData.productDate = QDate::fromString(root.attribute("issueDate"), sett().getDateFormat());
QDomNode tmp;
tmp = root.firstChild();
tmp = tmp.toElement().nextSibling(); // nabywca
nabywca = tmp.toElement();
o_invData.customer = nabywca.attribute("name") + "," + nabywca.attribute(
"city") + "," + nabywca.attribute("street") + "," + QObject::trUtf8("NIP: ")
+ nabywca.attribute("tic");
/* not required
+ ", " + nabywca.attribute("account")
+ ", " + nabywca.attribute("phone") + ", " + nabywca.attribute(
"email") + ", " + nabywca.attribute("www")) */
// kontrName->setCursorPosition(1);
tmp = tmp.toElement().nextSibling(); // product
product = tmp.toElement();
o_invData.discount = product.attribute("discount").toInt();
tmp = tmp.toElement().nextSibling();
QDomElement additional = tmp.toElement();
o_invData.additText = additional.attribute("text");
int curPayment = sett().value("payments").toString().split("|").indexOf(additional.attribute("paymentType"));
if (curPayment == sett().value("payments").toString().split("|").count() - 1) {
// disconnect(platCombo, SIGNAL(currentIndexChanged (QString)), this, SLOT(payTextChanged(QString)));
// platCombo->setCurrentIndex(curPayment);
// ; // = new CustomPaymData();
o_invData.custPaym.payment1 = additional.attribute("payment1");
o_invData.custPaym.amount1 = additional.attribute("amount1").toDouble();
o_invData.custPaym.date1 = QDate::fromString(additional.attribute("liabDate1"), sett().getDateFormat());
o_invData.custPaym.payment2 = additional.attribute("payment2");
o_invData.custPaym.amount2 = additional.attribute("amount2").toDouble();
o_invData.custPaym.date2 = QDate::fromString(additional.attribute("liabDate2"), sett().getDateFormat());
// connect(platCombo, SIGNAL(currentIndexChanged (QString)), this, SLOT(payTextChanged(QString)));
} else {
// platCombo->setCurrentIndex(curPayment);
}
o_invData.liabDate = QDate::fromString(additional.attribute("liabDate"), sett().getDateFormat());
int curCurrency = sett().value("waluty").toString().split("|").indexOf(additional.attribute("currency"));
o_invData.currencyTypeId = curCurrency;
QFile db(sett().getInvoicesDir() + name);
if (!db.open(QIODevice::ReadOnly | QIODevice::Text))
{
qDebug("file doesn't exist");
return o_invData;
}
QXmlQuery query;
QString res;
query.setFocus(&db);
query.setQuery("//product");
if ( ! query.isValid())
return o_invData;
query.evaluateTo(&res);
db.close();
QDomDocument productsDOMDocument;
productsDOMDocument.setContent("" + res + "");
QDomNodeList products = productsDOMDocument.elementsByTagName("product");
for (int i = 0; i < products.count(); i++) {
//.........这里部分代码省略.........