5
minidom을 사용하여 문서를 만들 때 속성은 요소에서 알파벳순으로 정렬됩니다. here에서이 예제를 보자XML 속성이 정렬됩니다.
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", "[email protected]")
userElem.setAttribute("photo","seocam.png")
# Append user element in xml document
xml.appendChild(userElem)
# Print the xml code
print xml.toprettyxml()
결과는 이것이다 : 당신이 대신 이름/별명의 이메일/이름/닉네임/사진 순서의 속성을 원한다면 아주 잘 모두이다
<?xml version="1.0" ?>
<user email="[email protected]" name="Sergio Oliveira" nickname="seocam" photo="seocam.png"/>
/이메일/사진 주문이 생성 된대로
속성을 생성 한 순서대로 표시하려면 어떻게합니까? 또는 주문을 어떻게 관리합니까?
왜 이것을 원하니? XML의 속성에는 정의와 달리 (요소와 달리) 순서가 없습니다. 그것은 단지 미화를위한 것일까 요? – Boldewyn
C-B-A 순서로 속성을 지정하는 XSD가 있고 A-B-C 순서로 만 wrie 할 수있는 경우 XSD를 만족합니까? – hughdbrown