#-*-Coding: UTF-8 -*- Import xml. dom. minidom ELEMENT_NODE = xml. dom. Node. ELEMENT_NODE Class SimpleXmlGetter (object ): Def _ init _ (self, data ): If type (data) = str: Self. root = xml. dom. minidom. parse (data) Else: Self. root = data Def _ getattr _ (self, name): # support. operation If name = 'data ': Return self. root. firstChild. data For c in self. root. childNodes: If c. nodeType = ELEMENT_NODE and c. tagName = name: Return SimpleXmlGetter (c) Def _ getitem _ (self, index): # support [] operation ENodes = [e for e in self. root. parentNode. childNodes If e. nodeType = ELEMENT_NODE and e. tagName = self. root. tagName] Return SimpleXmlGetter (eNodes [index]) Def _ call _ (self, * args, ** kwargs): # support () openration, for query conditions For e in self. root. parentNode. childNodes: If e. nodeType = ELEMENT_NODE: For key in kwargs. keys (): If e. getAttribute (key )! = Kwargs [key]: Break Else: Return SimpleXmlGetter (e) If _ name _ = "_ main __": X = SimpleXmlGetter ("sysd. xml ") Print x. sysd. sysagent. param [2]. data Print x. sysd. sysagent. param (name = "querytimeout", type = "second"). data |