当前位置:网站首页>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 " );
边栏推荐
- centos7.3修改mysql默认密码_详解Centos7 修改mysql指定用户的密码
- Squid 代理服务器之 ACL 访问控制
- Rod and Schwartz cooperated with ZhongGuanCun pan Lianyuan Institute to carry out 6G technology research and early verification
- jwt
- 云原生数据库VS传统数据库
- 左手梦想 右手责任 广汽本田不光关注销量 还有儿童安全
- mysql命令备份
- LINQ query (3)
- How do the TMUX color palette work?
- What is the reason for the disconnection of video playback due to the EHOME protocol access of easycvr platform?
猜你喜欢

如何通过EasyCVR接口监测日志观察平台拉流情况?

Redis 那些事

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

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

What are the reasons for the abnormal playback of the online channel of the channel accessed by easycvr national standard protocol?
![[live review] battle code pioneer phase 7: how third-party application developers contribute to open source](/img/ad/26a302ca724177e37fe123f8b75e4e.png)
[live review] battle code pioneer phase 7: how third-party application developers contribute to open source

做软件安全测试的作用,如何寻找软件安全测试公司出具报告?

Application of TSDB in civil aircraft industry

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

常用的软件测试工具清单,请查收。
随机推荐
Redistemplate operates redis. This article is enough (I) [easy to understand]
元宇宙的生态圈
把 Oracle 数据库从 Windows 系统迁移到 Linux Oracle Rac 集群环境(3)—— 把数据库设置为归档模式
Please run IDA with elevated permissons for local debugging.
EasyCVR国标协议接入的通道,在线通道部分播放异常是什么原因?
【第26天】给定 n 个元素的升序数组nums,求实现一个函数在nums中寻找target的下标 | 初识二分查找
When an interface has an exception, how do you analyze the exception?
[day 26] given the ascending array nums of n elements, find a function to find the subscript of target in nums | learn binary search
qt打包exe文件,解决“无法定位程序输入点_ZdaPvj于动态链接库Qt5Cored.dll”
Android Internet of things application development (smart Park) - set sensor threshold dialog interface
It's 2022, and you still don't know what performance testing is?
1-6搭建Win7虚拟机环境
MOS tube related knowledge
npm包发布详细教程
【Proteus仿真】Arduino UNO+数码管显示4x4键盘矩阵按键
云原生数据库VS传统数据库
如何卸载cuda
LINQ query (3)
一线城市软件测试工资——你拖后腿了吗
当一个接口出现异常时候,你是如何分析异常的?