Author: bugman Date: Sat Jun 28 20:45:06 2008 New Revision: 6528 URL: http://svn.gna.org/viewcvs/relax?rev=6528&view=rev Log: Wrote node_value_to_python() to convert the XML nodeValue to a python object. Modified: 1.3/data/relax_xml.py Modified: 1.3/data/relax_xml.py URL: http://svn.gna.org/viewcvs/relax/1.3/data/relax_xml.py?rev=6528&r1=6527&r2=6528&view=diff ============================================================================== --- 1.3/data/relax_xml.py (original) +++ 1.3/data/relax_xml.py Sat Jun 28 20:45:06 2008 @@ -64,6 +64,20 @@ sub_elem.appendChild(text_val) +def node_value_to_python(elem): + """Convert the node value to a python expression. + + @param elem: The XML element. + @type elem: xml.dom.minidom.Element instance + """ + + # Remove whitespace. + val = strip(elem.nodeValue) + + # Convert to python and return. + return eval(val) + + def xml_to_object(elem, base_object=None): """Convert the XML elements into python objects, and place these into the base object. @@ -83,7 +97,7 @@ name = str(node.localName) # Get the node contents. - val = eval(strip(node.childNodes[0].nodeValue)) + val = node_value_to_python(node.childNodes[0]) # Set the value. setattr(base_object, name, val)