当前位置: 首页>>代码示例>>C++>>正文


C++ QDomDocument::save方法代码示例

本文整理汇总了C++中QDomDocument::save方法的典型用法代码示例。如果您正苦于以下问题:C++ QDomDocument::save方法的具体用法?C++ QDomDocument::save怎么用?C++ QDomDocument::save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QDomDocument的用法示例。


在下文中一共展示了QDomDocument::save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: saveXMLFile

bool saveXMLFile(const QString& path, VirtualDataSceneData::XmlMap* map)
{
	QFile xmlFile(path);
	if (!xmlFile.open(QIODevice::WriteOnly | QIODevice::Text))
		return false;
	QDomDocument domTree;
	QDomText text;
	domTree.documentElement().clear();
	QDomProcessingInstruction instruction;
	instruction = domTree.createProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\"");
	domTree.appendChild(instruction);
	QDomElement mapElement = domTree.createElement(XML_ELEMENT_MAP);
	domTree.appendChild(mapElement);
	QDomElement eventsElement = domTree.createElement(XML_ELEMENT_EVENTS);
	mapElement.appendChild(eventsElement);
	QDomElement actorsElement = domTree.createElement(XML_ELEMENT_ACTORS);
	mapElement.appendChild(actorsElement);

	std::vector< VirtualDataSceneBase::ActorBase* > allActors;
	map->getAllActors(allActors);
	for (unsigned int i = 0; i < allActors.size(); ++i)
	{
		VirtualDataSceneBase::ActorBase* curActor = allActors.at(i);
		QDomElement actorElement = domTree.createElement(XML_ELEMENT_ACTOR);
		actorsElement.appendChild(actorElement);
		actorElement.setAttribute(XML_ELEMENT_TYPE, chineseTextUTF8ToQString(curActor->getClassName()));
		QDomElement actorIdElement = domTree.createElement(XML_ELEMENT_ID);
		text = domTree.createTextNode(chineseTextUTF8ToQString(curActor->getId()));
		actorIdElement.appendChild(text);
		actorElement.appendChild(actorIdElement);
		QDomElement actorNameElement = domTree.createElement(XML_ELEMENT_NAME);
		text = domTree.createTextNode(chineseTextUTF8ToQString(curActor->getActorName()));
		actorNameElement.appendChild(text);
		actorElement.appendChild(actorNameElement);
		//property
		std::vector< VirtualDataSceneBase::ActorProperty* > propertyList;
		curActor->getPropertyList(propertyList);
		for (unsigned int j = 0; j < propertyList.size(); ++j)
		{
			VirtualDataSceneBase::ActorProperty* curProperty = propertyList.at(j);
			QDomElement actorPropertyElement = domTree.createElement(XML_ELEMENT_PROPERTY);
			actorElement.appendChild(actorPropertyElement);
			QDomElement propertyNameElement = domTree.createElement(XML_ELEMENT_NAME);
			text = domTree.createTextNode(chineseTextUTF8ToQString(curProperty->getName()));
			propertyNameElement.appendChild(text);
			actorPropertyElement.appendChild(propertyNameElement);
			QDomElement propertyValueElement = domTree.createElement(chineseTextUTF8ToQString(curProperty->getDataType()));
			QString qTextValue = chineseTextUTF8ToQString(curProperty->toString());
			//if (qTextValue.contains('<') || qTextValue.contains('>') || qTextValue.contains('&') || qTextValue.contains('\'') || qTextValue.contains('"'))
			//	qTextValue = "<![CDATA[" + qTextValue + "]]>";
			text = domTree.createTextNode(qTextValue);
			propertyValueElement.appendChild(text);
			actorPropertyElement.appendChild(propertyValueElement);
		}
	}
	QTextStream out(&xmlFile);
	domTree.save(out, 4, QDomNode::EncodingFromTextStream);
	xmlFile.close();
	return true;
}
开发者ID:FreeDegree,项目名称:Zhang,代码行数:60,代码来源:ViewerUtil.cpp

示例2: writeXML

/**
* \brief This function save an \b XML \b file from a \b QDomDocument
* \author Jules Gorny - ALCoV team, ISIT, UMR 6284 UdA – CNRS
* \param filename : path of the file we will write
* \param XSDpath : path of the XSD file to check the xml validity
* \param doc : our xml tree in a QDomDocument
* \param indent : number of spaces for an indentation
*/
void writeXML(QString filename, QDomDocument doc, int indent)
{
	QFile file(filename);
	file.open(QIODevice::WriteOnly);
	QTextStream ts(&file);
	doc.save(ts, indent);
}
开发者ID:JulesGorny,项目名称:Medical-Data-Anonymization-DICOM-DCMTK,代码行数:15,代码来源:xmlTools.cpp

示例3: writeSetting

void readers::writeSetting(){
    QSettings sett("Skyrim", "lib");
    QString path(QString("%1/setting.xml").arg(sett.value("path").toString()));
    QFile file(path);
    QTextStream in(&file);
    QTextStream out(&file);

    QDomDocument doc;
    file.open(QIODevice::ReadOnly);
    doc.setContent(out.readAll());
    file.close();
    QDomNodeList node = doc.elementsByTagName("readers");
    node.item(0).attributes().namedItem("width").setNodeValue(QString("%1").arg(geometry().size().width()));
    node.item(0).attributes().namedItem("height").setNodeValue(QString("%1").arg(geometry().size().height()));
    node.item(0).attributes().namedItem("x").setNodeValue(QString("%1").arg(geometry().x()));
    node.item(0).attributes().namedItem("y").setNodeValue(QString("%1").arg(geometry().y()));
    node.item(0).attributes().namedItem("fam").setNodeValue(QString("%1").arg(ui.checkBox_fam->isChecked()));
    node.item(0).attributes().namedItem("ima").setNodeValue(QString("%1").arg(ui.checkBox_ima->isChecked()));
    node.item(0).attributes().namedItem("otc").setNodeValue(QString("%1").arg(ui.checkBox_otc->isChecked()));
    node.item(0).attributes().namedItem("date_r").setNodeValue(QString("%1").arg(ui.checkBox_data_r->isChecked()));
    node.item(0).attributes().namedItem("num").setNodeValue(QString("%1").arg(ui.checkBox_num->isChecked()));
    node.item(0).attributes().namedItem("phone").setNodeValue(QString("%1").arg(ui.checkBox_phone->isChecked()));
    node.item(0).attributes().namedItem("address").setNodeValue(QString("%1").arg(ui.checkBox_address->isChecked()));
    node.item(0).attributes().namedItem("doc").setNodeValue(QString("%1").arg(ui.checkBox_doc->isChecked()));
    file.open(QIODevice::WriteOnly);
    doc.save(out, 4);
    file.close();
}
开发者ID:Skyrim78,项目名称:Librarian,代码行数:28,代码来源:readers.cpp

示例4: mButtonExport_clicked

void QgsSubstitutionListWidget::mButtonExport_clicked()
{
  QString fileName = QFileDialog::getSaveFileName( this, tr( "Save substitutions" ), QDir::homePath(),
                     tr( "XML files (*.xml *.XML)" ) );
  if ( fileName.isEmpty() )
  {
    return;
  }

  // ensure the user never omitted the extension from the file name
  if ( !fileName.endsWith( QLatin1String( ".xml" ), Qt::CaseInsensitive ) )
  {
    fileName += QLatin1String( ".xml" );
  }

  QDomDocument doc;
  QDomElement root = doc.createElement( QStringLiteral( "substitutions" ) );
  root.setAttribute( QStringLiteral( "version" ), QStringLiteral( "1.0" ) );
  QgsStringReplacementCollection collection = substitutions();
  collection.writeXml( root, doc );
  doc.appendChild( root );

  QFile file( fileName );
  if ( !file.open( QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate ) )
  {
    QMessageBox::warning( nullptr, tr( "Export substitutions" ),
                          tr( "Cannot write file %1:\n%2." ).arg( fileName, file.errorString() ),
                          QMessageBox::Ok,
                          QMessageBox::Ok );
    return;
  }

  QTextStream out( &file );
  doc.save( out, 4 );
}
开发者ID:ccrook,项目名称:Quantum-GIS,代码行数:35,代码来源:qgssubstitutionlistwidget.cpp

示例5: file

bool FotowallFile::saveV2(const QString & fwFilePath, const Canvas * canvas)
{
    // create the document
    QDomDocument doc;
     doc.appendChild(doc.createProcessingInstruction("xml","version=\"1.0\" "));

    QDomElement rootElement = doc.createElement("fotowall");
     rootElement.setAttribute("format", 2);
     rootElement.setAttribute("version", QCoreApplication::applicationVersion());
     doc.appendChild(rootElement);

    QDomElement canvasElement = doc.createElement("canvas");
     rootElement.appendChild(canvasElement);

    // save current canvas
    Canvas * rwCanvas = (Canvas *)canvas;
    rwCanvas->setFilePath(fwFilePath);
    canvas->saveToXml(canvasElement);

    // open the file for writing
    QFile file(fwFilePath);
    if (!file.open(QIODevice::WriteOnly)) {
        QMessageBox::warning(0, QObject::tr("File Error"), QObject::tr("Error saving to the Fotowall file '%1'").arg(fwFilePath));
        return false;
    }

    // save in the file (2 indent spaces)
    QTextStream outStream(&file);
    doc.save(outStream, 2);
    file.close();

    // store a reference to the just written file
    App::settings->addRecentFotowallUrl(QUrl(fwFilePath));
    return true;
}
开发者ID:AndySardina,项目名称:fotowall,代码行数:35,代码来源:FotowallFile.cpp

示例6: touchDownloadTrashConfigFile

void XMLOperations::touchDownloadTrashConfigFile()
{
    QFile downloadTrashFile(DOWNLOADTRASHFILE_PATH);
    if (!downloadTrashFile.exists())
    {
        if (!downloadTrashFile.open(QIODevice::WriteOnly | QIODevice::Truncate))
        {
            return;
        }

        QDomDocument domDocument;

        QDomProcessingInstruction instruction;
        instruction=domDocument.createProcessingInstruction("xml","version=\'1.0\' encoding=\'UTF-8\'");

        domDocument.appendChild(instruction);

        //创建MainConfig根节点
        QDomElement downloadTrashNode = domDocument.createElement("DownloadTrashList");
        //添加元素节点到父节点
        domDocument.appendChild(downloadTrashNode);

        //写xml文件
        QTextStream textStream(&downloadTrashFile);

        domDocument.save(textStream,4);

        downloadTrashFile.close();
    }
}
开发者ID:Augus-Wang,项目名称:PointDownload,代码行数:30,代码来源:xmloperations.cpp

示例7: on_mExportColorsButton_clicked

void QgsRasterTerrainAnalysisDialog::on_mExportColorsButton_clicked()
{
  qWarning( "Export colors clicked" );
  QString file = QFileDialog::getSaveFileName( 0, tr( "Export Colors and elevations as xml" ), QDir::homePath() );
  if ( file.isEmpty() )
  {
    return;
  }

  QDomDocument doc;
  QDomElement reliefColorsElem = doc.createElement( "ReliefColors" );
  doc.appendChild( reliefColorsElem );

  QList< QgsRelief::ReliefColor > rColors = reliefColors();
  QList< QgsRelief::ReliefColor >::const_iterator rColorsIt = rColors.constBegin();
  for ( ; rColorsIt != rColors.constEnd(); ++rColorsIt )
  {
    QDomElement classElem = doc.createElement( "ReliefColor" );
    classElem.setAttribute( "MinElevation", QString::number( rColorsIt->minElevation ) );
    classElem.setAttribute( "MaxElevation", QString::number( rColorsIt->maxElevation ) );
    classElem.setAttribute( "red", QString::number( rColorsIt->color.red() ) );
    classElem.setAttribute( "green", QString::number( rColorsIt->color.green() ) );
    classElem.setAttribute( "blue", QString::number( rColorsIt->color.blue() ) );
    reliefColorsElem.appendChild( classElem );
  }

  QFile outputFile( file );
  if ( !outputFile.open( QIODevice::WriteOnly ) )
  {
    return;
  }
  QTextStream outStream( &outputFile );
  doc.save( outStream, 2 );
}
开发者ID:stevenmizuno,项目名称:QGIS,代码行数:34,代码来源:qgsrasterterrainanalysisdialog.cpp

示例8: insertDownloadTrash

void XMLOperations::insertDownloadTrash(SDownloadTrash tmpStruct)
{
    QDomDocument domDocument;
    QFile downloadTrashFile(DOWNLOADTRASHFILE_PATH);
    if (downloadTrashFile.open(QIODevice::ReadOnly))
    {
        // 此处需做错误判断
        if (!domDocument.setContent(&downloadTrashFile))
            return;
    }
    else
        return;

    downloadTrashFile.close();

    QDomElement fileElement = domDocument.createElement("File");

    fileElement.appendChild(createChildElement("Name", tmpStruct.name));
    fileElement.appendChild(createChildElement("URL", tmpStruct.URL));
    fileElement.appendChild(createChildElement("DLToolsType", tmpStruct.dlToolsType));
    fileElement.appendChild(createChildElement("TotalSize", tmpStruct.totalSize));
    fileElement.appendChild(createChildElement("IconPath",tmpStruct.iconPath));

    QDomElement rootElement = domDocument.documentElement();
    rootElement.appendChild(fileElement);

    //写xml文件
    if (!downloadTrashFile.open(QIODevice::WriteOnly | QIODevice::Truncate))
        return;
    QTextStream textStream(&downloadTrashFile);

    domDocument.save(textStream,4);

    downloadTrashFile.close();
}
开发者ID:Augus-Wang,项目名称:PointDownload,代码行数:35,代码来源:xmloperations.cpp

示例9: setValue

bool PkExampleHelper::setValue(const QString &action)
{
    // This action must be authorized first. It will set the implicit
    // authorization for the Shout action by editing the .policy file
    QDomDocument doc = QDomDocument("policy");
    QFile file("/usr/share/polkit-1/actions/org.qt.policykit.examples.policy");
    if (!file.open(QIODevice::ReadOnly))
        return false;
    doc.setContent(&file);
    file.close();
    QDomElement el = doc.firstChildElement("policyconfig").
                     firstChildElement("action");
    while (!el.isNull() && el.attribute("id", QString()) != "org.qt.policykit.examples.shout") {
        el = el.nextSiblingElement("action");
    }
    el = el.firstChildElement("defaults");
    el = el.firstChildElement("allow_active");
    if (el.isNull())
        return false;
    el.firstChild().toText().setData(action);
    if (!file.open(QIODevice::WriteOnly))
        return false;
    QTextStream stream(&file);
    doc.save(stream, 2);
    file.close();
    return true;
}
开发者ID:Schtrich,项目名称:polkit-qt-1,代码行数:27,代码来源:PkExampleHelper.cpp

示例10: file

ConnectDialog::~ConnectDialog(void)
{
    /* Aktuelle Werte als Default speichern */
    QFile file(m_configFile);

    if (file.open(QIODevice::WriteOnly))
    {
        QDomDocument doc;
        QDomElement root = doc.createElement("connection");
        doc.appendChild(root);

        QDomElement tag  = doc.createElement("host");
        QDomText    text = doc.createTextNode(m_ui->m_lineAddress->text());
        root.appendChild(tag);
        tag.appendChild(text);

        tag  = doc.createElement("port");
        text = doc.createTextNode(QString::number(m_ui->m_spinPort->value()));
        root.appendChild(tag);
        tag.appendChild(text);

        QTextStream stream(&file);
        doc.save(stream, 2);
        file.close();
    }
}
开发者ID:Knueppl,项目名称:emRHC,代码行数:26,代码来源:ConnectDialog.cpp

示例11: file

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    QFile file("test.xml");
    if(!file.open(QIODevice::WriteOnly | QIODevice::Truncate ))
        return;
    else
        qDebug()<<"ths file is existing!";
    QDomDocument doc;
    QDomText text;
    QDomProcessingInstruction instruction;
    instruction=doc.createProcessingInstruction("xml", "version = \'1.0\'");
    doc.appendChild(instruction);
    QDomElement school=doc.createElement("school");


    doc.appendChild(school);

    QDomElement schoolGuangMing=doc.createElement("schoolGuangMing");
    school.appendChild(schoolGuangMing);

    QDomElement grate1=doc.createElement("grate1");
    text=doc.createTextNode("一年级");
    grate1.appendChild(text);
    schoolGuangMing.appendChild(grate1);

    QDomElement student= doc.createElement("student1");
    QDomAttr name=doc.createAttribute("name");
    name.setValue("李明");
    QDomAttr number=doc.createAttribute("number");
    number.setValue("0x12313");
    student.setAttributeNode(name);
    student.setAttributeNode(number);
    schoolGuangMing.appendChild(student);


    QDomElement grate2=doc.createElement("grate2");
    text=doc.createTextNode("二年级");
    grate2.appendChild(text);
    schoolGuangMing.appendChild(grate2);

    QDomElement grate3=doc.createElement("grate3");
    text=doc.createTextNode("三年级");
    grate3.appendChild(text);
    schoolGuangMing.appendChild(grate3);

    QDomElement grate4=doc.createElement("grate4");
    text=doc.createTextNode("四年级");
    grate4.appendChild(text);
    schoolGuangMing.appendChild(grate4);

    QTextStream out( &file );

           doc.save( out, 7 );

        file.close();
}
开发者ID:squirrelClare,项目名称:algorithm_cplusplus,代码行数:60,代码来源:mainwindow.cpp

示例12: save

/**
 * 特徴量をxmlファイルに保存する。
 */
void GenericFeature::save(QString filename) {
	QDomDocument doc;

	QDomElement root = doc.createElement("features");
	doc.appendChild(root);

	QDomElement node_feature = doc.createElement("feature");
	node_feature.setAttribute("type", "generic");
	root.appendChild(node_feature);

	// write avenue node
	QDomElement node_avenue = doc.createElement("avenue");
	node_feature.appendChild(node_avenue);
	saveAvenue(doc, node_avenue);

	// write street node
	QDomElement node_street = doc.createElement("street");
	node_feature.appendChild(node_street);
	saveStreet(doc, node_street);

	// write the dom to the file
	QFile file(filename);
	file.open(QIODevice::WriteOnly);

	QTextStream out(&file);
	doc.save(out, 4);
}
开发者ID:gnishida,项目名称:RoadPatch,代码行数:30,代码来源:GenericFeature.cpp

示例13: deleteonescheduledata

void schedulexmldata::deleteonescheduledata(QString tmpscheduledate, QString tmpid)
{
    QFile file("/home/user/.scheduledata.xml");
    if(!file.open(QIODevice::ReadOnly))  return;
    QDomDocument doc;
    if(!doc.setContent(&file)){
        file.close();
        return;
    }
    file.close();

    QDomElement root = doc.documentElement();
    QDomNode n = root.firstChild();
    while(!n.isNull()){
        if(tmpscheduledate == n.toElement().attribute(QString("scheduledateattr"))){
            QDomNodeList schedulelist = n.toElement().elementsByTagName(QString("schedule"));
            for(int m=0; m<schedulelist.count(); m++){
                if(schedulelist.at(m).toElement().attribute(QString("id")) == tmpid){
                    qDebug() << n.toElement().tagName();
                    n.toElement().removeChild(schedulelist.at(m));
                }
            }
        }
        n = n.nextSibling();
    }

    if( !file.open(QIODevice::WriteOnly | QIODevice::Truncate)) return;
    QTextStream out(&file);
    doc.save(out, 4);
    file.close();
}
开发者ID:autumnViolet,项目名称:love,代码行数:31,代码来源:schedulexmldata.cpp

示例14: save

void FavouriteManagerPrivate::save()
{
    QDomDocument document;
    QDomElement rootElement = document.createElement("favourites");

    QListIterator<QPair<QString, Station> > iterator
            = QListIterator<QPair<QString, Station> >(data);
    while (iterator.hasNext()) {
        QPair<QString, Station> entry = iterator.next();
        QDomElement element = XmlConversionHelper::toXml(entry.second, &document);
        element.setAttribute(BACKEND_ATTRIBUTE, entry.first);
        rootElement.appendChild(element);
    }
    document.appendChild(rootElement);

    QDir favouriteDir = QDir(QDesktopServices::storageLocation(QDesktopServices::DataLocation));
    if (!favouriteDir.exists()) {
        QDir::root().mkpath(favouriteDir.absolutePath());
    }


    QFile file (favouriteDir.absoluteFilePath(fileName));
    if (!file.open(QIODevice::WriteOnly)) {
        return;
    }

    QTextStream stream(&file);
    document.save(stream, 2);
    file.close();
}
开发者ID:SfietKonstantin,项目名称:publictransportation-old,代码行数:30,代码来源:favouritemanager.cpp

示例15: ecrire

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();
}
开发者ID:gavalda,项目名称:CalcPolo,代码行数:31,代码来源:dom.cpp


注:本文中的QDomDocument::save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。