幫助文檔: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