python minidom混合元素属性

标签 python xml minidom

元素已创建:

        ele = doc.createElement("ele")   
        ele.attributes['var']= 'yes'
        ele.attributes['ret']= 'no'

        main.appendChild(ele)

但结果具有混合属性(可能按字母顺序):

<function ret="no" var="yes"/>

有什么方法可以保留minidom中属性的创建顺序吗?

最佳答案

没有。属性存储在字典中,并且不保留顺序。无论如何,这应该不重要,因为 XML 中属性的顺序没有语义意义。

您可以使用pxdom相反,如果您出于某种原因需要按顺序排列属性。

相关

关于python minidom混合元素属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10352858/

相关文章:

python - Django 和体育类(class)设计应用程序

xml - 元素 <Target> 中的属性 "Name"无法识别

xml - Apache commons 配置忽略最外层的 XML 标签?为什么?难道我做错了什么?

Python xml 迷你。生成 <text>Some text</text> 元素

python - celery 与 RabbitMQ : AttributeError: 'DisabledBackend' object has no attribute '_get_task_meta_for'

python - Xlwings:日期参数转换

android - 错误 : style attribute 'attr/colorPrimary' not found

Python minidom 获取子节点值时遇到问题

python : Replacing a HTML element depending on its content

java - 什么是CompoundCallable?