31 สิงหาคม 2558

Published สิงหาคม 31, 2558 by with 0 comment

โมดูล xmltodict

โมดูล xmltodict เป็นโมดูลสำหรับช่วยให้สามารถทำงานกับ XML ได้สะดวกยิ่งขึ้นเหมือนกับ JSON
รองรับทั้ง Python 2 , Python 3
ใช้ MIT License

สามารถติดตั้งไดโดยใช้คำสั่ง pip:
pip install xmltodict

ตัวอย่างการใช้งาน

[python]
>>> print(json.dumps(xmltodict.parse("""
... <mydocument has="an attribute">
... <and>
... <many>elements</many>
... <many>more elements</many>
... </and>
... <plus a="complex">
... element as well
... </plus>
... </mydocument>
... """), indent=4))
{
"mydocument": {
"@has": "an attribute",
"and": {
"many": [
"elements",
"more elements"
]
},
"plus": {
"@a": "complex",
"#text": "element as well"
}
}
}
[/python]

อ่านเอกสารการใช้งานได้ที่ https://github.com/martinblech/xmltodict
ขอบคุณครับ

0 ความคิดเห็น:

แสดงความคิดเห็น

แสดงความคิดเห็นได้ครับ :)