帮助文档:QXmlStreamReader、QXmlStreamWriterhtml
除此之外读取时还须要使用QXmlStreamAttributesapp
Constant | Value | Description |
---|---|---|
QXmlStreamReader::NoToken |
0 |
The reader has not yet read anything. |
QXmlStreamReader::Invalid |
1 |
An error has occurred, reported in error() and errorString(). |
QXmlStreamReader::StartDocument |
2 |
The reader reports the XML version number in documentVersion(), and the encoding as specified in the XML document in documentEncoding(). If the document is declared standalone, isStandaloneDocument() returns true ; otherwise it returns false . |
QXmlStreamReader::EndDocument |
3 |
The reader reports the end of the document. |
QXmlStreamReader::StartElement |
4 |
The reader reports the start of an element with namespaceUri() and name(). Empty elements are also reported as StartElement, followed directly by EndElement. The convenience function readElementText() can be called to concatenate all content until the corresponding EndElement. Attributes are reported in attributes(), namespace declarations in namespaceDeclarations(). |
QXmlStreamReader::EndElement |
5 |
The reader reports the end of an element with namespaceUri() and name(). |
QXmlStreamReader::Characters |
6 |
The reader reports characters in text(). If the characters are all white-space, isWhitespace() returns true . If the characters stem from a CDATA section, isCDATA() returns true . |
QXmlStreamReader::Comment |
7 |
The reader reports a comment in text(). |
QXmlStreamReader::DTD |
8 |
The reader reports a DTD in text(), notation declarations in notationDeclarations(), and entity declarations in entityDeclarations(). Details of the DTD declaration are reported in in dtdName(), dtdPublicId(), and dtdSystemId(). |
QXmlStreamReader::EntityReference |
9 |
The reader reports an entity reference that could not be resolved. The name of the reference is reported in name(), the replacement text in text(). |
QXmlStreamReader::ProcessingInstruction |
10 |
The reader reports a processing instruction in processingInstructionTarget() and processingInstructionData(). |
主要是用StartDocument
、EndDocument
文档开始结束,StartElement
、EndElement
元素开始结束、Characters
特征dom
第一行为StartDocument
函数
bookmark、title为StartElement
,/bookmark、/title为EndElement
spa
href为attributes的一项,能够有多项,经过QXmlStreamAttributes::value获取后面的地址内容指针
Qt Project是title这个element的charcterscode
写并不复杂,按顺序写便可,注意区分Attribute和Element,若是是一个小节用StartElement,若是是单行的相似于<title>Qt Project</title>能够直接用writeTextElement。orm
QXmlStreamWriter只是格式操做,并不提供文件操做,须要利用QFile创建文件并传递指针,也能够提供QString的指针,这样最终的xml信息会赋值到QString中。xml
除上述xml操做之外,Qt还提供了Qt XML模块,用于更高级的xml操做,提供了高速及使用便利的操做函数(不可兼得呀)htm
高速的SAX方法读取,QXmlSimpleReader及相关类
使用便捷的DOM方式:QDomDocument及相关类
使用这两个方法,因为是用的非core模块,须要在pro中添加qt += xml