hug*_*own 6 python xml minidom
当我使用minidom创建文档时,属性在元素中按字母顺序排序.从这里举个例子:
from xml.dom import minidom
# New document
xml = minidom.Document()
# Creates user element
userElem = xml.createElement("user")
# Set attributes to user element
userElem.setAttribute("name", "Sergio Oliveira")
userElem.setAttribute("nickname", "seocam")
userElem.setAttribute("email", "seocam@taboca.com")
userElem.setAttribute("photo","seocam.png")
# Append user element in xml document
xml.appendChild(userElem)
# Print the xml code
print xml.toprettyxml()
Run Code Online (Sandbox Code Playgroud)
结果是这样的:
<?xml version="1.0" ?>
<user email="seocam@taboca.com" name="Sergio Oliveira" nickname="seocam" photo="seocam.png"/>
Run Code Online (Sandbox Code Playgroud)
如果您想要创建电子邮件/名称/昵称/照片顺序中的属性而不是名称/昵称/电子邮件/照片顺序,那么这一切都非常好.
如何让属性按照您创建的顺序显示?或者,你如何控制订单呢?
| 归档时间: |
|
| 查看次数: |
1083 次 |
| 最近记录: |