ATLAS Offline Software
Classes | Functions | Variables
python.xmldict Namespace Reference

Classes

class  XmlDictObject
 module implementation ---------------------------------------------------— More...
 

Functions

def _dict2xml_recurse (parent, dictitem)
 
def dict2xml (xmldict)
 
def _xml2dict_recurse (node, dictclass)
 
def xml2dict (root, dictclass=XmlDictObject)
 

Variables

 __doc__
 
 __author__
 
 __all__
 module data -------------------------------------------------------------— More...
 

Function Documentation

◆ _dict2xml_recurse()

def python.xmldict._dict2xml_recurse (   parent,
  dictitem 
)
private

Definition at line 78 of file xmldict.py.

78 def _dict2xml_recurse(parent, dictitem):
79  assert type(dictitem) is not type(list)
80 
81  if isinstance(dictitem, dict):
82  for (tag, child) in dictitem.iteritems():
83  if isinstance(child, str):
84  child = _xml_escape(child)
85  if str(tag) == '_text':
86  parent.text = str(child)
87  elif type(child) is type(list):
88  for listchild in child:
89  elem = ElementTree.Element(tag)
90  parent.append(elem)
91  _dict2xml_recurse (elem, listchild)
92  else:
93  elem = ElementTree.Element(tag)
94  parent.append(elem)
95  _dict2xml_recurse (elem, child)
96  else:
97  parent.text = str(dictitem)
98 

◆ _xml2dict_recurse()

def python.xmldict._xml2dict_recurse (   node,
  dictclass 
)
private

Definition at line 106 of file xmldict.py.

106 def _xml2dict_recurse (node, dictclass):
107  nodedict = dictclass()
108 
109  if len(node.items()) > 0:
110  # if we have attributes, set them
111  nodedict.update(dict((k, _xml_unescape(v) if isinstance(v, str) else v)
112  for k,v in node.items()))
113 
114  for child in node:
115  # recursively add the element's children
116  newitem = _xml2dict_recurse (child, dictclass)
117  if isinstance(newitem, str):
118  newitem = _xml_unescape(newitem)
119  if child.tag in nodedict:
120  # found duplicate tag, force a list
121  if isinstance(nodedict[child.tag], list):
122  # append to existing list
123  nodedict[child.tag].append(newitem)
124  else:
125  # convert to list
126  nodedict[child.tag] = [nodedict[child.tag], newitem]
127  else:
128  # only one, directly set the dictionary
129  nodedict[child.tag] = newitem
130 
131  if node.text is None:
132  text = ''
133  else:
134  text = node.text.strip()
135 
136  if len(nodedict) > 0:
137  # if we have a dictionary add the text as a dictionary value
138  # (if there is any)
139  if len(text) > 0:
140  nodedict['_text'] = text
141  else:
142  # if we don't have child nodes or attributes, just set the text
143  if node.text: nodedict = node.text.strip()
144  else: nodedict = ""
145 
146  return nodedict
147 

◆ dict2xml()

def python.xmldict.dict2xml (   xmldict)
convert a python dictionary into an XML tree

Definition at line 99 of file xmldict.py.

99 def dict2xml(xmldict):
100  """convert a python dictionary into an XML tree"""
101  roottag = xmldict.keys()[0]
102  root = ElementTree.Element(roottag)
103  _dict2xml_recurse (root, xmldict[roottag])
104  return root
105 

◆ xml2dict()

def python.xmldict.xml2dict (   root,
  dictclass = XmlDictObject 
)
convert an xml tree into a python dictionary

Definition at line 148 of file xmldict.py.

148 def xml2dict (root, dictclass=XmlDictObject):
149  """convert an xml tree into a python dictionary
150  """
151  return dictclass({root.tag: _xml2dict_recurse (root, dictclass)})

Variable Documentation

◆ __all__

python.xmldict.__all__
private

module data -------------------------------------------------------------—

Definition at line 20 of file xmldict.py.

◆ __author__

python.xmldict.__author__
private

Definition at line 11 of file xmldict.py.

◆ __doc__

python.xmldict.__doc__
private

Definition at line 8 of file xmldict.py.

python.xmldict.dict2xml
def dict2xml(xmldict)
Definition: xmldict.py:99
dumpHVPathFromNtuple.append
bool append
Definition: dumpHVPathFromNtuple.py:91
python.xmldict.xml2dict
def xml2dict(root, dictclass=XmlDictObject)
Definition: xmldict.py:148
python.xmldict._xml2dict_recurse
def _xml2dict_recurse(node, dictclass)
Definition: xmldict.py:106
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
python.xmldict._dict2xml_recurse
def _dict2xml_recurse(parent, dictitem)
Definition: xmldict.py:78
str
Definition: BTagTrackIpAccessor.cxx:11