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 打赏 收藏 转发到动态 举报
写回复
用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
  • 打赏
  • 举报
回复
大概代码?帖代码吧

16,215

社区成员

发帖
与我相关
我的任务
社区描述
Qt 是一个跨平台应用程序框架。通过使用 Qt,您可以一次性开发应用程序和用户界面,然后将其部署到多个桌面和嵌入式操作系统,而无需重复编写源代码。
社区管理员
  • Qt
  • 亭台六七座
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧