ページ

2014年1月29日水曜日

xml ファイルの作成 :Qt


#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>
#include <QFile>
#include <QXmlStreamWriter>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QFile file("D:\\soft\\pleiades\\xampp\\htdocs\\www\\test.xml");
file.open(QIODevice::WriteOnly | QIODevice::Text);
QXmlStreamWriter stream(&file);
stream.setAutoFormatting(true);
stream.writeStartDocument();
stream.writeStartElement("root");
stream.writeStartElement("item");
stream.writeAttribute("name", "AAA");
stream.writeCharacters ("field1");
stream.writeEndElement();
stream.writeStartElement("item");
stream.writeAttribute("name", "BBB");
stream.writeCharacters ("field2");
stream.writeEndElement();
stream.writeEndDocument();//
file.close();
}
MainWindow::~MainWindow()
{
delete ui;
}
view raw mainwindow.cpp hosted with ❤ by GitHub
<?xml version="1.0" encoding="UTF-8"?>
<root>
<item name="AAA">field1</item>
<item name="BBB">field2</item>
</root>
view raw test.xml hosted with ❤ by GitHub



0 件のコメント:

コメントを投稿