我推荐我自己的食谱
它不能加速解析。但它提供了真正的本地对象样式访问。
>>> SAMPLE_XML = """<?xml version="1.0" encoding="UTF-8"?>
...
...
... fred
... 54321
... 12345
... "A]]>"
...
...
... """
>>> address_book = xml2obj(SAMPLE_XML)
>>> person = address_book.person
person.gender -> 'm' # an attribute
person['gender'] -> 'm' # alternative dictionary syntax
person.name -> 'fred' # shortcut to a text node
person.phone[0].type -> 'home' # multiple elements becomes an list
person.phone[0].data -> '54321' # use .data to get the text value
str(person.phone[0]) -> '54321' # alternative syntax for the text value
person[0] -> person # if there are only one , it can still
# be used as if it is a list of 1 element.
'address' in person -> False # test for existence of an attr or child
person.address -> None # non-exist element returns None
bool(person.address) -> False # has any 'address' data (attr, child or text)
person.note -> '"A "'