/** * reads an xml file from a specific location given by fileName * before reading from the output node QDomDocument::isNull() method value * should be checked. if it returns true then there is an error in reading file */ QDomDocument XMLWriter::retrieveFile(QString fileName) { QDomDocument domDoc; bool rdSuccess = true; QString errorMsg; int errorLine = 0; int errorColumn = 0; // read form file QFile file(fileName); if(file.open(QIODevice::ReadOnly | QIODevice::Text)) { rdSuccess = domDoc.setContent(&file, &errorMsg, &errorLine, &errorColumn); file.close(); }else{ qDebug()<< "Couldn't read from file " + file.fileName(); domDoc.clear(); } if(!rdSuccess){ qWarning() << "XML Read Error: " << errorMsg; qWarning() << "@line " << errorLine << "| @column " << errorColumn; domDoc.clear(); } return domDoc; }
int Creature::main(int argc, char** argv) { (void) argc; (void) argv; BasicCreature creature(1); QDomDocument doc; creature.toXml(doc); QString xml = doc.toString(); // std::cout << xml.toStdString() << std::endl; BDEBUG(xml.toStdString()); doc.clear(); QString * error_msg = new QString(); int* error_line = new int(); int* error_col = new int(); doc.setContent(xml, error_msg, error_line, error_col); std::cout << "Error: " << error_msg->toStdString() << " at [" << *error_line << " , " << *error_col << "]" << std::endl; delete error_msg; delete error_line; delete error_col; QDomElement root = doc.firstChild().toElement(); // creature.fromXml(root); doc.clear(); creature.toXml(doc); xml = doc.toString(); BDEBUG("******************************"); BDEBUG(xml.toStdString()); std::cout << xml.toStdString() << std::endl; return 0; }
void Dom::ecrire(QString fileName) { QFile file; QDomDocument doc; QDomElement sauvegarde; QDomElement racine; QTextStream out; doc.clear(); racine=doc.createElement("sauvegardes"); doc.appendChild(racine); // filiation de la balise "sauvegarde" file.setFileName(fileName); if (!file.open(QIODevice::WriteOnly)) // ouverture du fichier de sauvegarde return; // en écriture out.setDevice(&file); // association du flux au fichier for(int i=0; i<p.size(); i++){ sauvegarde=doc.createElement("sauvegarde"); sauvegarde.setAttribute("valeur", p.at(i)->toQString()); racine.appendChild(sauvegarde); } QDomNode noeud = doc.createProcessingInstruction("xml","version=\"1.0\""); doc.insertBefore(noeud,doc.firstChild()); // sauvegarde dans le flux (deux espaces de décalage dans l'arborescence) doc.save(out,2); file.close(); }
void saveState( QDomDocument &stateDoc ) const override { stateDoc.clear(); QDomElement documentElement = stateDoc.createElement( QStringLiteral( "UndoState" ) ); mLayout->writeXmlLayoutSettings( documentElement, stateDoc, QgsReadWriteContext() ); stateDoc.appendChild( documentElement ); }
//------------------------------------------------------------------------------ // QString QEMenuButtonModel::serialiseXml () const { QDomDocument doc; QDomElement docElem; doc.clear (); docElem = doc.createElement (mainTagName); docElem.setAttribute (versionAttrName, 1); doc.appendChild (docElem); // The core element is not serilaised, it is a model artefact. // This code snippet (~ 8 lines) mirrors QEMenuButtonItem::createDomElement. // const int n = this->coreItem->childCount (); for (int j = 0; j < n; j++) { QEMenuButtonItem* child = this->coreItem->getChild (j); if (child) { QDomElement childElement = child->createDomElement (doc); // recursive docElem.appendChild (childElement); } } // Remove newlines - designer's property manager does not handle properties // with many many lines very well. // return doc.toString ().replace ("\n", ""); }
void QgsComposerMultiFrameCommand::saveState( QDomDocument& stateDoc ) { if ( mMultiFrame ) { stateDoc.clear(); QDomElement documentElement = stateDoc.createElement( "ComposerMultiFrameState" ); mMultiFrame->writeXML( documentElement, stateDoc ); stateDoc.appendChild( documentElement ); } }
void QgsComposerItemCommand::saveState( QDomDocument& stateDoc ) const { if ( mItem ) { stateDoc.clear(); QDomElement documentElement = stateDoc.createElement( "ComposerItemState" ); mItem->writeXML( documentElement, stateDoc ); stateDoc.appendChild( documentElement ); } }
bool QgsWFSUtils::expressionToOGCFilter( QgsExpression& exp, QDomDocument& doc ) { doc.clear(); QDomElement filterElem = doc.createElement( "Filter" ); doc.appendChild( filterElem ); QgsExpressionOGCVisitor v( doc, filterElem ); exp.acceptVisitor( v ); return v.result(); }
void QgsLayoutItemUndoCommand::saveState( QDomDocument &stateDoc ) const { stateDoc.clear(); QDomElement documentElement = stateDoc.createElement( QStringLiteral( "ItemState" ) ); QgsLayoutItem *item = mLayout->itemByUuid( mItemUuid ); Q_ASSERT_X( item, "QgsLayoutItemUndoCommand::saveState", "could not retrieve item for saving state" ); item->writeXml( documentElement, stateDoc, QgsReadWriteContext() ); stateDoc.appendChild( documentElement ); }
bool QgsWFSUtils::expressionToOGCFilter( QgsExpression& exp, QDomDocument& doc ) { doc.clear(); QDomElement filterElem = doc.createElement( "Filter" ); filterElem.setAttribute( "xmlns:ogc", "http://www.opengis.net/ogc" ); doc.appendChild( filterElem ); QgsExpressionOGCVisitor v( doc, filterElem ); exp.acceptVisitor( v ); return v.result(); }
void QgsComposerItemCommand::saveState( QDomDocument& stateDoc ) const { const QgsComposerItem* source = item(); if ( !source ) { return; } stateDoc.clear(); QDomElement documentElement = stateDoc.createElement( "ComposerItemState" ); source->writeXML( documentElement, stateDoc ); stateDoc.appendChild( documentElement ); }
void UAList::Domify (QDomDocument & doc) { doc.clear (); QString emptyDoc ("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); emptyDoc.append ("\n"); emptyDoc.append ("<" + UA_FF::tag_File + " version=\"1.0\">\n"); emptyDoc.append ("</" + UA_FF::tag_File + ">\n"); doc.setContent (emptyDoc); QDomElement root = doc.documentElement (); AgentMapType::iterator it; for (it = agents.begin(); it != agents.end(); it++) { it->second->Domify (doc,root); } }
QStringList QWeather::getToday() { QDomDocument doc; doc.setContent(xmldoc); parcer(doc); doc.clear(); qDebug() << "today" << today_code; QList<QString> today; today.append(today_code); today.append(country); today.append(region); today.append(city); today.append(temperature); today.append(cf); today.append(condition); today.append(today_code); today.append(chill); today.append(humidity); today.append(pressure); return today; }
void QDomDocumentProto::clear() { QDomDocument *item = qscriptvalue_cast<QDomDocument*>(thisObject()); if (item) item->clear(); }
// if no file is open void MainWindow::openFile(QString &xmlFileName, QFile &xmlFile, QDomDocument &xmlDomDocument, QDomDocument &xmlDomDocumentOrg, bool createFile) { QString filename; // open file diaglog if(createFile == OPEN_EXISTING_FILE){ // Open diaglog to -- open existing file filename = QFileDialog::getOpenFileName(this, tr("Open File"), "", tr("Files (*.xml)")); } else{ // Open diaglog to -- create new file filename = QFileDialog::getSaveFileName(this, tr("Save File"), "", tr("Files (*.xml)")); } // Check if cancel button is pressed in the QFileDialog if(filename != "") { //copy file name to globalobject xmlFileName = filename; // create new xml file & text stream //xmlOpenFile(); // Add a delay xmlLibObject.xmlOpenFile( xmlFileName, xmlFile, xmlStream); if(createFile == OPEN_EXISTING_FILE){ //Load the XML file //xmlLoadFile(); xmlLibObject.xmlLoadFile(xmlDomDocument, xmlFile); //close file //xmlCloseFile(); //xmlLibObject.xmlCloseFile(xmlStream, xmlDomDocument, xmlFile); //Now again open & truncate the file //xmlOpenFileTruncate(); //xmlLibObject.xmlOpenFileTruncate( xmlFileName, xmlFile, xmlStream); //Get the root element //xmlGetRoot(); xmlLibObject.xmlGetRoot(xmlRoot, xmlDomDocument); // copy data to the tree view // copy data to the text view loadXmltoTreeAndTextView(); //Its not new file b_newFileCreationSignal = FALSE; //create backup for original xml. xmlDomDocumentOrg.clear(); xmlDomDocumentOrg = xmlDomDocument.cloneNode(true).toDocument(); } else{ //Add root node //xmlAddRoot(); xmlLibObject.xmlAddRoot(xmlRoot, xmlDomDocument); // File contains new node b_fileDoesNotContainsNode = TRUE; //New file creation signal b_newFileCreationSignal = TRUE; //New file created xmlDomDocumentOrg.clear(); } // xml file is already open b_xmlFileAlreadyOpen = TRUE; } else { // Do nothing cancel presses } }