当前位置:网站首页>Using qdomdocument to manipulate XML files in QT
Using qdomdocument to manipulate XML files in QT
2022-06-25 02:18:00 【Chenziqing: see】
Catalog
(1) establish xml Document format header
(2) Create root node element labels
(3) Create child node element labels
(1) Find all node elements for a specific tagName
(2) QDomNodeList Class introduction
(6) obtain QDomNode Two methods of attribute value
The header file
qmake: QT += xmlHeader: #include<QDomDocument>
QDomDocument --> xml The file pointer
Associated files
QFile file(filePath);
file.open(QIODevice::WriteOnly);
QDomDocument doc;
doc.setContent(&file);
XML Writing files
(1) establish xml Document format header
QDomProcessingInstruction ins;
ins = doc.createProcessingInstruction("xml", "version = \'1.0\' encoding=\'utf-8\'");
(2) Create root node element labels
QDomElement root = doc.createElement("tagname");
doc.appendChild(root);
(3) Create child node element labels
QDomElement dateEmt = doc.createElement("childTagName");
root.appendChild(dateEmt);
(4) Set tag properties
QDomElement dateEmt = doc.createElement("cim:Company");
// Create attribute name
QDomAttr dateAttr = doc.createAttribute(" Property name ");
dateAttr.setNodeValue(" Property content ”);dateEmt.setAttributeNode(dateAttr); // Set tag properties
(5) Set label content
QDomText text = doc.createTextNode("xxx");
dateEmt.appendChild(text);
(6) preservation xml file
QTextStream stream(&file);
doc.save(stream, 4); // Parameters 2 by Labeled tab Indent value
XML File analysis
(1) Find all node elements for a specific tagName
QDomNodeList nodeList = doc.elementsByTagName(" Tag name ")
(2) QDomNodeList Class introduction
QDomNodeList Class is QDomNode List of objects .
Header:
#include <QDomNodeList>
qmake:
QT += xml
- List of all members , Including inherited members
Note: All functions in this class are reentrant.
Public Functions
QDomNodeList(const QDomNodeList &n)
QDomNode
at(int index) const
int
count() const
bool
isEmpty() const
QDomNode
item(int index) const
int
length() const
int
size() const
bool
operator!=(const QDomNodeList &n) const
QDomNodeList &
operator=(const QDomNodeList &n)
bool
operator==(const QDomNodeList &n) const
QDomNodeList Class is QDomNode List of objects .
The list can be through QDomDocument::elementsByTagName() and QDomNode::childNodes() get . Document object model (DOM) These lists are required to be “ Activities of the ”: Whenever you change the underlying document , The contents of the list will be updated .
have access to item() Get a specific node from the list . The number of items in the list is determined by length() return
(3)QDomNode Class method
QDomNode()
QDomNode(const QDomNode &n)
QDomNode
appendChild(const QDomNode &newChild)
QDomNamedNodeMap
attributes() const
QDomNodeList
childNodes() const
void
clear()
QDomNode
cloneNode(bool deep = true) const
int
columnNumber() const
QDomNode
firstChild() const
QDomElement
firstChildElement(const QString &tagName = QString()) const
bool
hasAttributes() const
bool
hasChildNodes() const
QDomNode
insertAfter(const QDomNode &newChild, const QDomNode &refChild)
QDomNode
insertBefore(const QDomNode &newChild, const QDomNode &refChild)
bool
isAttr() const
bool
isCDATASection() const
bool
isCharacterData() const
bool
isComment() const
bool
isDocument() const
bool
isDocumentFragment() const
bool
isDocumentType() const
bool
isElement() const
bool
isEntity() const
bool
isEntityReference() const
bool
isNotation() const
bool
isNull() const
bool
isProcessingInstruction() const
bool
isSupported(const QString &feature, const QString &version) const
bool
isText() const
QDomNode
lastChild() const
QDomElement
lastChildElement(const QString &tagName = QString()) const
int
lineNumber() const
QString
localName() const
QDomNode
namedItem(const QString &name) const
QString
namespaceURI() const
QDomNode
nextSibling() const
QDomElement
nextSiblingElement(const QString &tagName = QString()) const
QString
nodeName() const
NodeType
nodeType() const
QString
nodeValue() const
void
QDomDocument
ownerDocument() const
QDomNode
parentNode() const
QString
prefix() const
QDomNode
previousSibling() const
QDomElement
previousSiblingElement(const QString &tagName = QString()) const
QDomNode
removeChild(const QDomNode &oldChild)
QDomNode
replaceChild(const QDomNode &newChild, const QDomNode &oldChild)
void
save(QTextStream &stream, int indent, EncodingPolicy encodingPolicy = QDomNode::EncodingFromDocument) const
void
setNodeValue(const QString &v)
void
setPrefix(const QString &pre)
QDomAttr
toAttr() const
QDomCDATASection
toCDATASection() const
QDomCharacterData
toCharacterData() const
QDomComment
toComment() const
QDomDocument
toDocument() const
QDomDocumentFragment
toDocumentFragment() const
QDomDocumentType
toDocumentType() const
QDomElement
toElement() const
QDomEntity
toEntity() const
QDomEntityReference
toEntityReference() const
QDomNotation
toNotation() const
QDomProcessingInstruction
toProcessingInstruction() const
QDomText
toText() const
bool
operator!=(const QDomNode &n) const
QDomNode &
operator=(const QDomNode &n)
bool
operator==(const QDomNode &n) const
(4) Traversal node
Use firstChild() Get the first child node of the node ( If there is ), And use nextSibling() Traversal .
(5) QDomElement And QDomNode
I understand it : QDomElement and QDomNode It's all nodes , Difference is that QDomElement Is a separate node ( That is, when there are no sub tags ), have access to tagName() and text() Method to get the name and content of the node . QDomNode have access to toElement() Turn into QDomElement type
(6) obtain QDomNode Two methods of attribute value
QDomNode node;
① QString value = node.attributes().namedItem(" Property name ").nodeValue()
② QString value = QDomElement elem = node.toElement().attribute( " Property name " );
边栏推荐
- LINQ 查询(3)
- Redistemplate operates redis. This article is enough (I) [easy to understand]
- Talking about the advantages of flying book in development work | community essay solicitation
- 内网学习笔记(7)
- 2022-06-24:golang选择题,以下golang代码输出什么?A:1;B:3;C:4;D:编译失败。 package main import ( “f
- What are the reasons for the abnormal playback of the online channel of the channel accessed by easycvr national standard protocol?
- 非凸联合创始人李佐凡:将量化作为自己的终身事业
- Multimodal emotion recognition_ Research on emotion recognition based on multimodal fusion
- Constant current circuit composed of 2 NPN triodes
- 【移动端】手机界面的设计尺寸
猜你喜欢

EasyCVR国标协议接入的通道,在线通道部分播放异常是什么原因?

华为、阿里等大厂程序员真的好找对象吗?

入坑机器学习:一,绪论

Experience of epidemic prevention and control, home office and online teaching | community essay solicitation

业务与技术双向结合构建银行数据安全管理体系

Dataease template market officially released

非凸联合创始人李佐凡:将量化作为自己的终身事业

【直播回顾】战码先锋第七期:三方应用开发者如何为开源做贡献

高速缓存Cache详解(西电考研向)

【Proteus仿真】Arduino UNO+数码管显示4x4键盘矩阵按键
随机推荐
Sumati gamefi ecological overview, element design in the magical world
Experience of epidemic prevention and control, home office and online teaching | community essay solicitation
华为、阿里等大厂程序员真的好找对象吗?
internship:svn的使用
centos7.3修改mysql默认密码_详解Centos7 修改mysql指定用户的密码
Are programmers from Huawei, Alibaba and other large manufacturers really easy to find?
同花顺是正规平台吗?同花顺开户安全吗
Once beego failed to find bee after passing the go get command Exe's pit
When an interface has an exception, how do you analyze the exception?
商城项目 pc----商品详情页
Sumati GameFi生态纵览,神奇世界中的元素设计
How to get the picture outside the chain - Netease photo album [easy to understand]
Kaggle 专利匹配比赛金牌方案赛后总结
云原生数据库VS传统数据库
How to monitor the log through the easycvr interface to observe the platform streaming?
左手梦想 右手责任 广汽本田不光关注销量 还有儿童安全
Intranet learning notes (5)
【STL源码剖析】配置器(待补充)
内网学习笔记(6)
Stocking but not completely stocking (daily question 2 in spring)