- <?xmlversion="1.0"encoding="UTF-8"?>
- <Startaniminal="cat">
- book>book1</Start>
simpleWriter.cpp
- #include<QXmlStreamWriter>
- #include<QFile>
- #include<iostream>
- usingnamespacestd;
- voidwriteXML(){
- QFilefile("test.xml");
- if(notfile.open(QIODevice::ReadWrite))
- return;
- QXmlStreamWriterwriter(&file);
- writer.setAutoFormatting(true);
- writer.writeStartDocument();
- writer.writeStartElement("Start");
- writer.writeAttribute("animinal","cat");
- writer.writeTextElement("book","book1");
- writer.writeEndElement();//Start
- writer.writeEndDocument();
- file.close();
- }
- intmain(){
- writeXML();
- }