社区
Qt
帖子详情
Qt生成XML文件节点中的属性顺序错乱的问题
yulingrqz
2013-05-31 04:10:57
用QDomDocument实现生成一个XML文件,
其中一个节点<pNode>按照如下顺序生成属性:
id,name,desc,width,height
但是生成的文件格式却是类似这样的:
<pNode width="200" name="ceshi" id="1" desc="" height="300"></pNode>
也就是说节点中的属性顺序不是按照代码中写入的顺序存储的,请问各位大神,这是怎么回事?该怎么解决?
...全文
2379
11
打赏
收藏
Qt生成XML文件节点中的属性顺序错乱的问题
用QDomDocument实现生成一个XML文件, 其中一个节点按照如下顺序生成属性: id,name,desc,width,height 但是生成的文件格式却是类似这样的: 也就是说节点中的属性顺序不是按照代码中写入的顺序存储的,请问各位大神,这是怎么回事?该怎么解决?
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
11 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
一把顺子
2015-06-05
打赏
举报
回复
是把属性当做子节点输出吗?
drCoding
2014-07-01
打赏
举报
回复
这个可以用node解决么?
理智聪明
2013-10-08
打赏
举报
回复
楼主怎么解决的呢
JohnBoy
2013-07-31
打赏
举报
回复
楼主,我也遇到这个问题,到底该怎么解决啊,能说详细点吗?
polokang
2013-07-13
打赏
举报
回复
我也遇到类似的问题,替换属性值并重新生成新的xml 以后,发现标签属性的顺序全颠倒了。。。 不知道如何解决!?
yulingrqz
2013-06-04
打赏
举报
回复
谢谢您的解答! 按照属性名当然是可以解析的,但是现在是有这样的需求,要按照顺序输出属性名和属性值,而不关心属性名是什么。 看来只能是改用node了。
ppdayz
2013-06-03
打赏
举报
回复
xml的Attribute属性是无关排序的,怎么排都是一样的,对于解析都没哟影响的。 所以一般的dom处理的库都是随机或者是按照其内定的排序的。 排序不排序都不影响解析的,不知道你要求排序是为了什么?好看? 所以如果你特别需求要顺序的话,把Attribute变成node。
yulingrqz
2013-05-31
打赏
举报
回复
是这样的: <picnode fullScreen="false" x="0" desc="" y="0" disHeight="600" borderStyle="0" picHeight="600" disWidth="900" picWidth="900" name="ffess" disStyle="0" ifScroll="false"></picnode>
yulingrqz
2013-05-31
打赏
举报
回复
生成的文体<picnode>节点如下: <picnode fullScreen="false" x="0" desc="" y="0" disHeight="600" borderStyle="0" picHeight="600" disWidth="900" picWidth="900" name="ffess" disStyle="0" ifScroll="false">
yulingrqz
2013-05-31
打赏
举报
回复
代码如下所示: void Q_CustomClass::saveToXml(QDomDocument &doc, QDomElement root) { QString sValue; QDomElement element; element = doc.createElement("picnode"); sValue = m_stAttribute.picName; QDomAttr Attr = doc.createAttribute(tr("name")); Attr.setValue(sValue); element.setAttributeNode(Attr); sValue = m_stAttribute.picDesc; Attr = doc.createAttribute(tr("desc")); Attr.setValue(sValue); element.setAttributeNode(Attr); sValue = QString::number(m_stAttribute.picX); Attr = doc.createAttribute(tr("x")); Attr.setValue(sValue); element.setAttributeNode(Attr); sValue = QString::number(m_stAttribute.picY); Attr = doc.createAttribute(tr("y")); Attr.setValue(sValue); element.setAttributeNode(Attr); sValue = QString::number(m_stAttribute.disWidth); Attr = doc.createAttribute(tr("disWidth")); Attr.setValue(sValue); element.setAttributeNode(Attr); sValue = QString::number(m_stAttribute.disHeight); Attr = doc.createAttribute(tr("disHeight")); Attr.setValue(sValue); element.setAttributeNode(Attr); sValue = QString::number(m_stAttribute.picWidth); Attr = doc.createAttribute(tr("picWidth")); Attr.setValue(sValue); element.setAttributeNode(Attr); sValue = QString::number(m_stAttribute.picHeight); Attr = doc.createAttribute(tr("picHeight")); Attr.setValue(sValue); element.setAttributeNode(Attr); sValue = QString::number(m_stAttribute.picDisStyle); Attr = doc.createAttribute(tr("disStyle")); Attr.setValue(sValue); element.setAttributeNode(Attr); sValue = QString::number(m_stAttribute.picBorderStyle); Attr = doc.createAttribute(tr("borderStyle")); Attr.setValue(sValue); element.setAttributeNode(Attr); if (true == m_stAttribute.fullScreen) { sValue = "true"; } else { sValue = "false"; } Attr = doc.createAttribute(tr("fullScreen")); Attr.setValue(sValue); element.setAttributeNode(Attr); if (true == m_stAttribute.ifScroll) { sValue = "true"; } else { sValue = "false"; } Attr = doc.createAttribute(tr("ifScroll")); Attr.setValue(sValue); element.setAttributeNode(Attr); root.appendChild(element); }
海的神话
2013-05-31
打赏
举报
回复
大概代码?帖代码吧
Qt
中
使用QDomDocument
生成
XML文件
元素
属性
随机乱序解决办法
大多数情况下都是这么创建
节点
并插入
属性
的。 QDomDocument xmlFile; QDomProcessingInstruction instruction = xmlFile.createProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\""); xmlFile.appendChild(instruction); ...
使用
Qt
的QDomAttr类进行XML
属性
操作
除了访问和修改
属性
的值之外,QDomAttr类还提供了其他一些有用的方法,例如获取
属性
的名称和拥有该
属性
的元素对象。然后,我们使用createAttribute()方法创建了一个名为"Version"的
属性
,并设置了
属性
值为"1.0"。在
Qt
中
,QDomAttr类提供了一种方便的方式来处理XML文档
中
的
属性
。然后,我们可以使用QDomElement类的attributeNode()方法来获得一个
属性
的QDomAttr对象。除了访问和修改
属性
的值之外,QDomAttr类还提供了其他一些有用的方法。
Qt
Xml文件
的创建和解析[xml和dom方式]
Qt
Xml文件
的创建和解析[xml和dom方式] 【1】
Qt
XML使用说明 【2】
Qt
XML未来可期 【3】
Qt
XML文件
格式 【4】
Qt
读取XML文档的方法 【5】
Qt
XML解析方式比较 【6】QXmlStreamReader类说明 【7】QXmlStreamWriter类说明 【8】DOM说明 【9】XML常用函数 【10】DOM常用函数 【11】XML和DOM源码 XML.pro mainwindow.h mainwindow.cpp 【12】XML和DOM运行结果和输出
Hello
Qt
(四十一)——
XML文件
解析总结
一、
XML文件
解析方式的特点 1、DOM解析XML文档的特点 基于DOM的解析器的核心是在内存
中
建立和XML文档相对应的树状结构。
XML文件
的标记、标记
中
的文本数据和实体等都是内存
中
的树状结构的某个
节点
相对应。 优点:可以方便地操作内存
中
的树状
节点
缺点:如果
XML文件
较大,或者只需要解析XML文档的一部分数据,就会占用大量的内存空间 2、SAX解析XML文档的特点 SAX解析的核心是事件处理机制,SAX采用事件机制的方式来解析XML文档。使用SAX解析器对XML文档进行解析时,SAX解析器根本
Qt
解析XML
用
Qt
中
的QDomDocument类处理
XML文件
XML,全称为扩展标记语言(extensible markup language).是一种非常方便的数据交换工具。现在Blog的订阅系统输出格式就是满足XML规范的RSS格式,还有SVG矢量图形也使用了XML格式。 我们在取得一个XML格式的文件后,需要作句法分析去提取发布方提供的信息。而
Qt
为XML提供了很好的支持,包括DOM的实现和SAX的实现。 DOM 是Document Object Model的简称,其实现方式是将整个文档当作一个对象来装入内存进
Qt
16,215
社区成员
26,594
社区内容
发帖
与我相关
我的任务
Qt
Qt 是一个跨平台应用程序框架。通过使用 Qt,您可以一次性开发应用程序和用户界面,然后将其部署到多个桌面和嵌入式操作系统,而无需重复编写源代码。
复制链接
扫一扫
分享
社区描述
Qt 是一个跨平台应用程序框架。通过使用 Qt,您可以一次性开发应用程序和用户界面,然后将其部署到多个桌面和嵌入式操作系统,而无需重复编写源代码。
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章