Index: src/sans/dataloader/readers/cansas_constants.py
===================================================================
--- src/sans/dataloader/readers/cansas_constants.py	(revision 9e2bc6c924661a1b972fc7d9cbf2c5a29138df07)
+++ src/sans/dataloader/readers/cansas_constants.py	(revision ac5b69d317038c3025e6c4a3397e52b2a3012a79)
@@ -3,16 +3,20 @@
 the cansas_reader.py file to read in any version of the cansas format.
 """
-class cansasConstants:
-    
-    ns = ''
+class CansasConstants:
+    """
+    The base class to define where all of the data is to be saved by
+    cansas_reader.py.
+    """
+    
+    names = ''
     format = ''
     
     
     def __init__(self):
-        self.ns = self.CANSAS_NS
+        self.names = self.CANSAS_NS
         self.format = self.CANSAS_FORMAT
     
     
-    def _iterate_namespace(self, namespace):
+    def iterate_namespace(self, namespace):
         """
         Method to iterate through a cansas constants tree based on a list of
@@ -23,5 +27,5 @@
         """
         # The current level to look through in cansas_constants.
-        return_me = currentLevel()
+        return_me = CurrentLevel()
         return_me.current_level = self.CANSAS_FORMAT.get("SASentry")
         # Defaults for variable and datatype
@@ -30,23 +34,28 @@
         return_me.ns_optional = True
         for name in namespace:
-            if name != "SASentry":
-                return_me.current_level = \
-                        return_me.current_level.get("children").get(name, "")
-                if return_me.current_level == "":
+            try:
+                if name != "SASentry":
                     return_me.current_level = \
-                            return_me.current_level.get("<any>", "")
-                cl_variable = return_me.current_level.get("variable", "")
-                cl_datatype = return_me.current_level.get("storeas", "")
-                cl_units_optional = \
-                            return_me.current_level.get("units_required", "")
-                # Where are how to store the variable for the given namespace
-                # CANSAS_CONSTANTS tree is hierarchical, so is no value, inherit
-                return_me.ns_variable = cl_variable if cl_variable != "" else \
-                                    return_me.ns_variable
-                return_me.ns_datatype = cl_datatype if cl_datatype != "" else \
-                                    return_me.ns_datatype
-                return_me.ns_optional = cl_units_optional if \
-                                    cl_units_optional != return_me.ns_optional \
-                                    else return_me.ns_optional
+                            return_me.current_level.get("children").get(name, "")
+                    if return_me.current_level == "":
+                        return_me.current_level = \
+                                return_me.current_level.get("<any>", "")
+                    cl_variable = return_me.current_level.get("variable", "")
+                    cl_datatype = return_me.current_level.get("storeas", "")
+                    cl_units_optional = \
+                                return_me.current_level.get("units_required", "")
+                    # Where are how to store the variable for the given namespace
+                    # CANSAS_CONSTANTS tree is hierarchical, so is no value, inherit
+                    return_me.ns_variable = cl_variable if cl_variable != "" else \
+                                        return_me.ns_variable
+                    return_me.ns_datatype = cl_datatype if cl_datatype != "" else \
+                                        return_me.ns_datatype
+                    return_me.ns_optional = cl_units_optional if \
+                                        cl_units_optional != return_me.ns_optional \
+                                        else return_me.ns_optional
+            except AttributeError:
+                return_me.ns_variable = "{0}.meta_data[\"{2}\"] = \"{1}\""
+                return_me.ns_datatype = "content"
+                return_me.ns_optional = True
         return return_me    
     
@@ -454,8 +463,10 @@
                            }
     SASINSTR_SRC = {
-                    "attributes" : {"name" : {"variable" : "{0}.source.name = \"{1}\""}},
+                    "attributes" : {"name" : {"variable" : \
+                                              "{0}.source.name = \"{1}\""}},
                     "variable" : None,
                     "children" : {
-                                  "radiation" : {"variable" : "{0}.source.radiation = \"{1}\""},
+                                  "radiation" : {"variable" : \
+                                            "{0}.source.radiation = \"{1}\""},
                                   "beam_size" : SASINSTR_SRC_BEAMSIZE,
                                   "beam_shape" : {"variable" : \
@@ -647,5 +658,6 @@
                         "unit" : "pixel_size_unit",
                         "attributes" : {
-                                        "unit" : "{0}.pixel_size_unit = \"{1}\"",
+                                        "unit" : \
+                                            "{0}.pixel_size_unit = \"{1}\"",
                                         "storeas" : "content"
                                         }
@@ -655,5 +667,6 @@
                         "unit" : "pixel_size_unit",
                         "attributes" : {
-                                        "unit" : "{0}.pixel_size_unit = \"{1}\"",
+                                        "unit" : \
+                                            "{0}.pixel_size_unit = \"{1}\"",
                                         "storeas" : "content"
                                         }
@@ -663,5 +676,6 @@
                         "unit" : "pixel_size_unit",
                         "attributes" : {
-                                        "unit" : "{0}.pixel_size_unit = \"{1}\"",
+                                        "unit" : \
+                                            "{0}.pixel_size_unit = \"{1}\"",
                                         "storeas" : "content"
                                         }
@@ -740,5 +754,8 @@
                      }
    
-class currentLevel:
+class CurrentLevel:
+    """
+    A helper class to hold information on where you are in the constants tree
+    """
      
     current_level = ''
@@ -748,5 +765,5 @@
      
     def __init__(self):
-        self.current_level = ''
+        self.current_level = {}
         self.ns_variable = ''
         self.ns_datatype = "content"
Index: src/sans/dataloader/readers/cansas_reader.py
===================================================================
--- src/sans/dataloader/readers/cansas_reader.py	(revision 2e3b055365667cec714d68e643c78a70e38b9f85)
+++ src/sans/dataloader/readers/cansas_reader.py	(revision ac5b69d317038c3025e6c4a3397e52b2a3012a79)
@@ -18,4 +18,6 @@
 import sys
 import datetime
+import inspect
+# For saving individual sections of data
 from sans.dataloader.data_info import Data1D
 from sans.dataloader.data_info import Collimation
@@ -24,6 +26,9 @@
 from sans.dataloader.data_info import Process
 from sans.dataloader.data_info import Aperture
+# Both imports used. Do not remove either.
+from xml.dom.minidom import parseString
 import sans.dataloader.readers.xml_reader as xml_reader
-from sans.dataloader.readers.cansas_constants import cansasConstants
+from sans.dataloader.readers.xml_reader import XMLreader
+from sans.dataloader.readers.cansas_constants import CansasConstants
 
 _ZERO = 1e-16
@@ -36,10 +41,16 @@
     HAS_CONVERTER = False
 
-constants = cansasConstants()    
-CANSAS_FORMAT = constants.format
-CANSAS_NS = constants.ns
+CONSTANTS = CansasConstants()    
+CANSAS_FORMAT = CONSTANTS.format
+CANSAS_NS = CONSTANTS.names
 ALLOW_ALL = True
 
 
+# minidom used in functions called by outside classes
+import xml.dom.minidom
+# DO NOT REMOVE
+# Called by outside packages:
+#    sans.perspectives.invariant.invariant_state
+#    sans.perspectives.fitting.pagestate
 def get_content(location, node):
     """
@@ -51,5 +62,6 @@
     :return: Element, or None
     """
-    nodes = node.xpath(location, namespaces={'ns': CANSAS_NS})
+    nodes = node.xpath(location, 
+                       namespaces={'ns': CANSAS_NS.get("1.0").get("ns")})
     
     if len(nodes) > 0:
@@ -59,30 +71,7 @@
 
 
-def get_float(location, node):
-    """
-    Get the content of a node as a float
-    
-    :param location: xpath location
-    :param node: node to start at
-    """
-    nodes = node.xpath(location, namespaces={'ns': CANSAS_NS})
-    
-    value = None
-    attr = {}
-    if len(nodes) > 0:
-        try:
-            value = float(nodes[0].text)
-        except:
-            # Could not pass, skip and return None
-            msg = "cansas_reader.get_float: could not "
-            msg += " convert '%s' to float" % nodes[0].text
-            logging.error(msg)
-        if nodes[0].get('unit') is not None:
-            attr['unit'] = nodes[0].get('unit')
-    return value, attr
-
-
-# This is called by sans.perspectives.fitting.pagestate.py
-# Do not remove
+# DO NOT REMOVE
+# Called by outside packages:
+#    sans.perspectives.fitting.pagestate
 def write_node(doc, parent, name, value, attr={}):
     """
@@ -105,5 +94,5 @@
                 
 
-class Reader():
+class Reader(XMLreader):
     """
     Class to load cansas 1D XML files
@@ -114,15 +103,13 @@
     ##CanSAS version - defaults to version 1.0
     cansas_version = "1.0"
-    ##Data reader
-    # TODO: make the reader extend the XMLreader class?
-    reader = xml_reader.XMLreader()
+    
+    logging = []
     errors = []
     
     type_name = "canSAS"
-    
     ## Wildcards
-    type = ["XML files (*.xml)|*.xml"]
+    type = ["XML files (*.xml)|*.xml", "SasView Save Files (*.svs)|*.svs"]
     ## List of allowed extensions
-    ext = ['.xml', '.XML']
+    ext = ['.xml', '.XML', '.svs', '.SVS']
     
     ## Flag to bypass extension check
@@ -133,14 +120,16 @@
         self.errors = []
         
-    def is_cansas(self):
+    def is_cansas(self, ext="xml"):
         """
         Checks to see if the xml file is a CanSAS file
         """
-        if self.reader.validateXML():
+        if self.validate_xml():
             name = "{http://www.w3.org/2001/XMLSchema-instance}schemaLocation"
-            value = self.reader.xmlroot.get(name)
-            if (CANSAS_NS.get(self.cansas_version).get("ns") == \
-                    value.rsplit(" ")[0]):
+            value = self.xmlroot.get(name)
+            if CANSAS_NS.get(self.cansas_version).get("ns") == \
+                    value.rsplit(" ")[0]:
                 return True
+        if ext == "svs":
+            return True
         return False
     
@@ -152,8 +141,8 @@
         """
         # X - Q value; Y - Intensity (Abs)
-        x = numpy.empty(0)
-        y = numpy.empty(0)
-        dx = numpy.empty(0)
-        dy = numpy.empty(0)
+        x_vals = numpy.empty(0)
+        y_vals = numpy.empty(0)
+        dx_vals = numpy.empty(0)
+        dy_vals = numpy.empty(0)
         dxl = numpy.empty(0)
         dxw = numpy.empty(0)
@@ -162,5 +151,5 @@
         output = []
         # ns - Namespace hierarchy for current xml object
-        ns = []
+        ns_list = []
         
         # Check that the file exists
@@ -168,6 +157,7 @@
             basename = os.path.basename(xml)
             _, extension = os.path.splitext(basename)
-            # If the fiel type is not allowed, return nothing
+            # If the file type is not allowed, return nothing
             if extension in self.ext or self.allow_all:
+                # Get the file location of 
                 base_name = xml_reader.__file__
                 base_name = base_name.replace("\\","/")
@@ -175,6 +165,6 @@
                 
                 # Load in xml file and get the cansas version from the header
-                self.reader.setXMLFile(xml)
-                root = self.reader.xmlroot
+                self.set_xml_file(xml)
+                root = self.xmlroot
                 if root is None:
                     root = {}
@@ -187,14 +177,14 @@
                 
                 # Link a schema to the XML file.
-                self.reader.setSchema(schema_path)
+                self.set_schema(schema_path)
                 
                 # Try to load the file, but raise an error if unable to.
                 # Check the file matches the XML schema
                 try:
-                    if self.is_cansas():
+                    if self.is_cansas(extension):
                         # Get each SASentry from XML file and add it to a list.
                         entry_list = root.xpath('/ns:SASroot/ns:SASentry',
                                 namespaces={'ns': cansas_defaults.get("ns")})
-                        ns.append("SASentry")
+                        ns_list.append("SASentry")
                         
                         # If multiple files, modify the name for each is unique
@@ -204,6 +194,7 @@
                         # Parse each SASentry item
                         for entry in entry_list:
-                            # Define a new Data1D object with zeroes for x and y
-                            data1d = Data1D(x,y,dx,dy)
+                            # Define a new Data1D object with zeroes for 
+                            # x_vals and y_vals
+                            data1d = Data1D(x_vals, y_vals, dx_vals, dy_vals)
                             data1d.dxl = dxl
                             data1d.dxw = dxw
@@ -220,11 +211,11 @@
                             
                             # Get all preprocessing events and encoding
-                            self.reader.setProcessingInstructions()
+                            self.set_processing_instructions()
                             data1d.meta_data[PREPROCESS] = \
-                                    self.reader.processingInstructions
+                                    self.processing_instructions
                             
                             # Parse the XML file
                             return_value, extras = \
-                                self._parse_entry(entry, ns, data1d)
+                                self._parse_entry(entry, ns_list, data1d)
                             del extras[:]
                             
@@ -251,14 +242,14 @@
                             output.append(return_value)
                     else:
-                        value = self.reader.findInvalidXML()
+                        value = self.find_invalid_xml()
                         output.append("Invalid XML at: {0}".format(value))
                 except:
                     # If the file does not match the schema, raise this error
-                    raise RuntimeError, "%s cannot be read \increment" % xml
+                    raise RuntimeError, "%s cannot be read" % xml
                 return output
         # Return a list of parsed entries that dataloader can manage
         return None
     
-    def _create_unique_key(self, dictionary, name, i = 0):
+    def _create_unique_key(self, dictionary, name, numb = 0):
         """
         Create a unique key value for any dictionary to prevent overwriting
@@ -267,11 +258,11 @@
         :param dictionary: A dictionary with any number of entries
         :param name: The index of the item to be added to dictionary
-        :param i: The number to be appended to the name, starts at 0
+        :param numb: The number to be appended to the name, starts at 0
         """
         if dictionary.get(name) is not None:
-            i += 1
+            numb += 1
             name = name.split("_")[0]
-            name += "_{0}".format(i)
-            name = self._create_unique_key(dictionary, name, i)
+            name += "_{0}".format(numb)
+            name = self._create_unique_key(dictionary, name, numb)
         return name
     
@@ -284,5 +275,5 @@
         
         :param new_current_level: cansas_constants level as returned by 
-            _iterate_namespace
+            iterate_namespace
         :param attr: The attributes of the node
         :param data1d: Where the values will be saved
@@ -318,5 +309,6 @@
                             return
                         except:
-                            err_msg = "CanSAS reader: could not convert the units"
+                            err_msg = \
+                                "CanSAS reader: could not convert the units"
                             self.errors.append(err_msg)
                             return
@@ -343,5 +335,5 @@
         return node_value, value_unit
     
-    def _parse_entry(self, dom, ns, data1d, extras = []):
+    def _parse_entry(self, dom, names=["SASentry"], data1d=None, extras=[]):
         """
         Parse a SASEntry - new recursive method for parsing the dom of
@@ -349,12 +341,23 @@
             and extra nodes to be read in simultaneously.
         
-        :param dom: dom object with a namespace base of ns
-        :param ns: A list of element names that lead up to the dom object
+        :param dom: dom object with a namespace base of names
+        :param names: A list of element names that lead up to the dom object
         :param data1d: The data1d object that will be modified
         :param extras: Any values that should go into meta_data when data1d
             is not a Data1D object
         """
-         
+        
         # A portion of every namespace entry
+        if data1d == None:
+            x_vals = numpy.empty(0)
+            y_vals = numpy.empty(0)
+            dx_vals = numpy.empty(0)
+            dy_vals = numpy.empty(0)
+            dxl = numpy.empty(0)
+            dxw = numpy.empty(0)
+            data1d = Data1D(x_vals, y_vals, dx_vals, dy_vals)
+            data1d.dxl = dxl
+            data1d.dxw = dxw
+                            
         base_ns = "{0}{1}{2}".format("{", \
                             CANSAS_NS.get(self.cansas_version).get("ns"), "}")
@@ -366,10 +369,14 @@
         for node in dom:
             try:
-                # Get the element name and set the current ns level
+                # Get the element name and set the current names level
                 tagname = node.tag.replace(base_ns, "")
                 tagname_original = tagname
-                ns.append(tagname)
+                if tagname == "fitting_plug_in":
+                    continue
+                names.append(tagname)
                 attr = node.attrib
                 children = node.getchildren()
+                if len(children) == 0:
+                    children = None
                 save_data1d = data1d
                 
@@ -410,10 +417,11 @@
                                 
                 # Get where to store content
-                cs_values = constants._iterate_namespace(ns)
+                cs_values = CONSTANTS.iterate_namespace(names)
                 # If the element is a child element, recurse
                 if children is not None:
                     # Returned value is new Data1D object with all previous and 
                     # new values in it.
-                    data1d, extras = self._parse_entry(node, ns, data1d, extras)
+                    data1d, extras = self._parse_entry(node, 
+                                                       names, data1d, extras)
                     
                 #Get the information from the node
@@ -488,5 +496,5 @@
                             pass
             
-            except TypeError:
+            except TypeError as e:
                 pass
             except Exception as e:
@@ -509,10 +517,11 @@
                 else:
                     save_data1d = data1d
-                data1d = save_data1d
-                # Remove tagname from ns to restore original base
-                ns.remove(tagname_original)
-        
+                if tagname_original != "fitting_plug_in":
+                    data1d = save_data1d
+                    # Remove tagname from names to restore original base
+                    names.remove(tagname_original)
         return data1d, extras
         
+    
     def _to_xml_doc(self, datainfo):
         """
@@ -526,9 +535,13 @@
         
         # Get PIs and create root element
-        pis = self.reader.return_processing_instructions()
-        doc = self.reader.create_tree(pis[0])
-        i = 1
-        for i in range(1,len(pis) - 1):
-            doc = self.reader.append(pis[i], doc)
+        pis = self.return_processing_instructions()
+        if len(pis) > 0:
+            pi_tree = self.create_tree(pis[0])
+            i = 1
+            for i in range(1,len(pis) - 1):
+                pi_tree = self.append(pis[i], pi_tree)
+            pi_string = self.to_string(pi_tree)
+        else:
+            pi_string = ""
         
         # Define namespaces and create SASroot object
@@ -540,21 +553,20 @@
         else:
             url = "http://svn.smallangles.net/svn/canSAS/1dwg/trunk/"
-        schemaLocation = "{0} {1}cansas1d.xsd".format(ns, url)
-        attrib = {"{" + xsi + "}schemaLocation" : schemaLocation,
+        schema_location = "{0} {1}cansas1d.xsd".format(ns, url)
+        attrib = {"{" + xsi + "}schemaLocation" : schema_location,
                   "version" : version}
         nsmap = {'xsi' : xsi, None: ns}
         
-        main_node = self.reader.create_element("{" + ns + "}SASroot", \
+        main_node = self.create_element("{" + ns + "}SASroot", \
                                                attrib = attrib, \
                                                nsmap = nsmap)
         
         # Create ElementTree, append SASroot and apply processing instructions
-        base_string = self.reader.toString(doc) + \
-                    self.reader.toString(main_node)
-        base_element = self.reader.create_element_from_string(base_string)
-        doc = self.reader.create_tree(base_element)
+        base_string = pi_string + self.to_string(main_node)
+        base_element = self.create_element_from_string(base_string)
+        doc = self.create_tree(base_element)
         
         # Create SASentry Element
-        entry_node = self.reader.create_element("SASentry")
+        entry_node = self.create_element("SASentry")
         root = doc.getroot()
         root.append(entry_node)
@@ -576,9 +588,9 @@
         
         # Data info
-        node = self.reader.create_element("SASdata")
-        self.reader.append(node, entry_node)
+        node = self.create_element("SASdata")
+        self.append(node, entry_node)
         
         for i in range(len(datainfo.x)):
-            pt = self.reader.create_element("Idata")
+            pt = self.create_element("Idata")
             node.append(pt)
             self.write_node(pt, "Q", datainfo.x[i], {'unit': datainfo.x_unit})
@@ -598,15 +610,15 @@
                 self.write_node(pt, "dQl", datainfo.dxl[i],
                             {'unit': datainfo.x_unit})
-
+        
         # Transmission Spectrum Info
         for i in range(len(datainfo.trans_spectrum)):
             spectrum = datainfo.trans_spectrum[i]
-            node = self.reader.create_element("SAStransmission_spectrum",
+            node = self.create_element("SAStransmission_spectrum",
                                               {"name" : spectrum.name})
-            self.reader.append(node, entry_node)
+            self.append(node, entry_node)
             if isinstance(spectrum.timestamp, datetime.datetime):
                 node.setAttribute("timestamp", spectrum.timestamp)
             for i in range(len(spectrum.wavelength)):
-                pt = self.reader.create_element("Tdata")
+                pt = self.create_element("Tdata")
                 node.append(pt)
                 self.write_node(pt, "Lambda", spectrum.wavelength[i], 
@@ -621,10 +633,10 @@
 
         # Sample info
-        sample = self.reader.create_element("SASsample")
+        sample = self.create_element("SASsample")
         if datainfo.sample.name is not None:
-            self.reader.write_attribute(sample, 
+            self.write_attribute(sample, 
                                         "name", 
                                         str(datainfo.sample.name))
-        self.reader.append(sample, entry_node)
+        self.append(sample, entry_node)
         self.write_node(sample, "ID", str(datainfo.sample.ID))
         self.write_node(sample, "thickness", datainfo.sample.thickness,
@@ -634,5 +646,5 @@
                    {"unit": datainfo.sample.temperature_unit})
         
-        pos = self.reader.create_element("position")
+        pos = self.create_element("position")
         written = self.write_node(pos, 
                                   "x", 
@@ -648,7 +660,7 @@
                                        {"unit": datainfo.sample.position_unit})
         if written == True:
-            self.reader.append(pos, sample)
-        
-        ori = self.reader.create_element("orientation")
+            self.append(pos, sample)
+        
+        ori = self.create_element("orientation")
         written = self.write_node(ori, "roll",
                                   datainfo.sample.orientation.x,
@@ -661,5 +673,5 @@
                                     {"unit": datainfo.sample.orientation_unit})
         if written == True:
-            self.reader.append(ori, sample)
+            self.append(ori, sample)
         
         for item in datainfo.sample.details:
@@ -667,23 +679,23 @@
         
         # Instrument info
-        instr = self.reader.create_element("SASinstrument")
-        self.reader.append(instr, entry_node)
+        instr = self.create_element("SASinstrument")
+        self.append(instr, entry_node)
         
         self.write_node(instr, "name", datainfo.instrument)
         
         #   Source
-        source = self.reader.create_element("SASsource")
+        source = self.create_element("SASsource")
         if datainfo.source.name is not None:
-            self.reader.write_attribute(source,
+            self.write_attribute(source,
                                         "name",
                                         str(datainfo.source.name))
-        self.reader.append(source, instr)
+        self.append(source, instr)
         if datainfo.source.radiation == None or datainfo.source.radiation == '':
             datainfo.source.radiation = "neutron"
         self.write_node(source, "radiation", datainfo.source.radiation)
         
-        size = self.reader.create_element("beam_size")
+        size = self.create_element("beam_size")
         if datainfo.source.beam_size_name is not None:
-            self.reader.write_attribute(size,
+            self.write_attribute(size,
                                         "name",
                                         str(datainfo.source.beam_size_name))
@@ -697,5 +709,5 @@
                                        {"unit": datainfo.source.beam_size_unit})
         if written == True:
-            self.reader.append(size, source)
+            self.append(size, source)
             
         self.write_node(source, "beam_shape", datainfo.source.beam_shape)
@@ -718,8 +730,8 @@
             datainfo.collimation.append(coll)
         for item in datainfo.collimation:
-            coll = self.reader.create_element("SAScollimation")
+            coll = self.create_element("SAScollimation")
             if item.name is not None:
-                self.reader.write_attribute(coll, "name", str(item.name))
-            self.reader.append(coll, instr)
+                self.write_attribute(coll, "name", str(item.name))
+            self.append(coll, instr)
             
             self.write_node(coll, "length", item.length,
@@ -727,14 +739,14 @@
             
             for apert in item.aperture:
-                ap = self.reader.create_element("aperture")
+                ap = self.create_element("aperture")
                 if apert.name is not None:
-                    self.reader.write_attribute(ap, "name", str(apert.name))
+                    self.write_attribute(ap, "name", str(apert.name))
                 if apert.type is not None:
-                    self.reader.write_attribute(ap, "type", str(apert.type))
-                self.reader.append(ap, coll)
-                
-                size = self.reader.create_element("size")
+                    self.write_attribute(ap, "type", str(apert.type))
+                self.append(ap, coll)
+                
+                size = self.create_element("size")
                 if apert.size_name is not None:
-                    self.reader.write_attribute(size, 
+                    self.write_attribute(size, 
                                                 "name", 
                                                 str(apert.size_name))
@@ -746,5 +758,5 @@
                                                {"unit": apert.size_unit})
                 if written == True:
-                    self.reader.append(size, ap)
+                    self.append(size, ap)
                 
                 self.write_node(ap, "distance", apert.distance,
@@ -758,12 +770,12 @@
                 
         for item in datainfo.detector:
-            det = self.reader.create_element("SASdetector")
+            det = self.create_element("SASdetector")
             written = self.write_node(det, "name", item.name)
             written = written | self.write_node(det, "SDD", item.distance,
                                            {"unit": item.distance_unit})
             if written == True:
-                self.reader.append(det, instr)
+                self.append(det, instr)
             
-            off = self.reader.create_element("offset")
+            off = self.create_element("offset")
             written = self.write_node(off, "x", item.offset.x,
                                  {"unit": item.offset_unit})
@@ -773,7 +785,7 @@
                                            {"unit": item.offset_unit})
             if written == True:
-                self.reader.append(off, det)
-                
-            ori = self.reader.create_element("orientation")
+                self.append(off, det)
+                
+            ori = self.create_element("orientation")
             written = self.write_node(ori, "roll", item.orientation.x,
                                  {"unit": item.orientation_unit})
@@ -785,7 +797,7 @@
                                            {"unit": item.orientation_unit})
             if written == True:
-                self.reader.append(ori, det)
+                self.append(ori, det)
             
-            center = self.reader.create_element("beam_center")
+            center = self.create_element("beam_center")
             written = self.write_node(center, "x", item.beam_center.x,
                                  {"unit": item.beam_center_unit})
@@ -797,7 +809,7 @@
                                            {"unit": item.beam_center_unit})
             if written == True:
-                self.reader.append(center, det)
-                
-            pix = self.reader.create_element("pixel_size")
+                self.append(center, det)
+                
+            pix = self.create_element("pixel_size")
             written = self.write_node(pix, "x", item.pixel_size.x,
                                  {"unit": item.pixel_size_unit})
@@ -810,10 +822,10 @@
                                            {"unit": item.slit_length_unit})
             if written == True:
-                self.reader.append(pix, det)
+                self.append(pix, det)
             
         # Processes info
         for item in datainfo.process:
-            node = self.reader.create_element("SASprocess")
-            self.reader.append(node, entry_node)
+            node = self.create_element("SASprocess")
+            self.append(node, entry_node)
 
             self.write_node(node, "name", item.name)
@@ -831,19 +843,30 @@
         # Note info
         if len(datainfo.notes) == 0:
-            node = self.reader.create_element("SASnote")
-            self.reader.append(node, entry_node)
+            node = self.create_element("SASnote")
+            self.append(node, entry_node)
         else:
             for item in datainfo.notes:
-                node = self.reader.create_element("SASnote")
-                self.reader.write_text(node, item)
-                self.reader.append(node, entry_node)
+                node = self.create_element("SASnote")
+                self.write_text(node, item)
+                self.append(node, entry_node)
                 
         
         # Return the document, and the SASentry node associated with
         # the data we just wrote
+        
+        frm = inspect.stack()[1]
+        mod = inspect.getmodule(frm[0])
+        mod_name = mod.__name__
+        if mod_name != "sans.dataloader.readers.cansas_reader":
+            string = self.to_string(doc, pp=True)
+            doc = parseString(string)
+            node_name = entry_node.tag
+            node_list = doc.getElementsByTagName(node_name)
+            entry_node = node_list.item(0)
+        
         return doc, entry_node
     
     
-    def write_node(self, parent, name, value, attr={}):
+    def write_node(self, parent, name, value, attr=None):
         """
         :param doc: document DOM
@@ -856,5 +879,5 @@
         """
         if value is not None:
-            parent = self.reader.ebuilder(parent, name, value, attr)
+            parent = self.ebuilder(parent, name, value, attr)
             return True
         return False
@@ -872,8 +895,92 @@
         # Write the file
         fd = open(filename, 'w')
-        if self.reader.encoding == None:
-            self.reader.encoding = "UTF-8"
-        doc.write(fd, encoding=self.reader.encoding,
+        if self.encoding == None:
+            self.encoding = "UTF-8"
+        doc.write(fd, encoding=self.encoding,
                   pretty_print=True, xml_declaration=True)
         fd.close()
     
+    
+    # DO NOT REMOVE - used in saving and loading panel states.
+    def _store_float(self, location, node, variable, storage, optional=True):
+        """
+        Get the content of a xpath location and store
+        the result. Check that the units are compatible
+        with the destination. The value is expected to
+        be a float.
+        
+        The xpath location might or might not exist.
+        If it does not exist, nothing is done
+       
+        :param location: xpath location to fetch
+        :param node: node to read the data from
+        :param variable: name of the data member to store it in [string]
+        :param storage: data object that has the 'variable' data member
+        :param optional: if True, no exception will be raised
+            if unit conversion can't be done
+
+        :raise ValueError: raised when the units are not recognized
+        """
+        entry = get_content(location, node)
+        try:
+            value = float(entry.text)
+        except:
+            value = None
+            
+        if value is not None:
+            # If the entry has units, check to see that they are
+            # compatible with what we currently have in the data object
+            units = entry.get('unit')
+            if units is not None:
+                toks = variable.split('.')
+                local_unit = None
+                exec "local_unit = storage.%s_unit" % toks[0]
+                if local_unit != None and units.lower() != local_unit.lower():
+                    if HAS_CONVERTER == True:
+                        try:
+                            conv = Converter(units)
+                            exec "storage.%s = %g" % (variable,
+                                           conv(value, units=local_unit))
+                        except:
+                            err_mess = "CanSAS reader: could not convert"
+                            err_mess += " %s unit [%s]; expecting [%s]\n  %s" \
+                                % (variable, units, local_unit, sys.exc_value)
+                            self.errors.append(err_mess)
+                            if optional:
+                                logging.info(err_mess)
+                            else:
+                                raise ValueError, err_mess
+                    else:
+                        err_mess = "CanSAS reader: unrecognized %s unit [%s];"\
+                        % (variable, units)
+                        err_mess += " expecting [%s]" % local_unit
+                        self.errors.append(err_mess)
+                        if optional:
+                            logging.info(err_mess)
+                        else:
+                            raise ValueError, err_mess
+                else:
+                    exec "storage.%s = value" % variable
+            else:
+                exec "storage.%s = value" % variable
+                
+    
+    # DO NOT REMOVE - used in saving and loading panel states.
+    def _store_content(self, location, node, variable, storage):
+        """
+        Get the content of a xpath location and store
+        the result. The value is treated as a string.
+        
+        The xpath location might or might not exist.
+        If it does not exist, nothing is done
+        
+        :param location: xpath location to fetch
+        :param node: node to read the data from
+        :param variable: name of the data member to store it in [string]
+        :param storage: data object that has the 'variable' data member
+        
+        :return: return a list of errors
+        """
+        entry = get_content(location, node)
+        if entry is not None and entry.text is not None:
+            exec "storage.%s = entry.text.strip()" % variable
Index: src/sans/dataloader/readers/xml_reader.py
===================================================================
--- src/sans/dataloader/readers/xml_reader.py	(revision 2e3b055365667cec714d68e643c78a70e38b9f85)
+++ src/sans/dataloader/readers/xml_reader.py	(revision ac5b69d317038c3025e6c4a3397e52b2a3012a79)
@@ -17,7 +17,15 @@
 from lxml import etree
 from lxml.builder import E
-parser = etree.ETCompatXMLParser(remove_comments=True, remove_pis=False)
+
+PARSER = etree.ETCompatXMLParser(remove_comments=True, remove_pis=False)
 
 class XMLreader():
+    """
+    Generic XML read and write class. Mostly helper functions.
+    Makes reading/writing XML a bit easier than calling lxml libraries directly.
+    
+    :Dependencies:
+        This class requires lxml 2.3 or higher.
+    """
     
     xml = None
@@ -27,17 +35,17 @@
     schemadoc = None
     encoding = None
-    processingInstructions = None
+    processing_instructions = None
     
     def __init__(self, xml = None, schema = None, root = None):
         self.xml = xml
         self.schema = schema
-        self.processingInstructions = {}
+        self.processing_instructions = {}
         if xml is not None:
-            self.setXMLFile(xml, root)
+            self.set_xml_file(xml, root)
         else:
             self.xmldoc = None
             self.xmlroot = None
         if schema is not None:
-            self.setSchema(schema)
+            self.set_schema(schema)
         else:
             self.schemadoc = None
@@ -47,11 +55,11 @@
         Read in an XML file into memory and return an lxml dictionary
         """
-        if self.validateXML():
-            self.xmldoc = etree.parse(self.xml, parser = parser)
+        if self.validate_xml():
+            self.xmldoc = etree.parse(self.xml, parser = PARSER)
         else:
-            raise etree.ValidationError(self, self.findInvalidXML())
+            raise etree.XMLSchemaValidateError(self, self.find_invalid_xml())
         return self.xmldoc
     
-    def setXMLFile(self, xml, root = None):
+    def set_xml_file(self, xml, root = None):
         """
         Set the XML file and parse
@@ -59,5 +67,5 @@
         try:
             self.xml = xml
-            self.xmldoc = etree.parse(self.xml, parser = parser)
+            self.xmldoc = etree.parse(self.xml, parser = PARSER)
             self.xmlroot = self.xmldoc.getroot()
         except Exception:
@@ -66,5 +74,5 @@
             self.xmlroot = None
     
-    def setSchema(self, schema):
+    def set_schema(self, schema):
         """
         Set the schema file and parse
@@ -72,10 +80,10 @@
         try:
             self.schema = schema
-            self.schemadoc = etree.parse(self.schema, parser = parser)
+            self.schemadoc = etree.parse(self.schema, parser = PARSER)
         except Exception:
             self.schema = None
             self.schemadoc = None
     
-    def validateXML(self):
+    def validate_xml(self):
         """
         Checks to see if the XML file meets the schema
@@ -83,30 +91,30 @@
         valid = True
         if self.schema is not None:
-            self.parseSchemaAndDoc()
-            schemaCheck = etree.XMLSchema(self.schemadoc)
-            valid = schemaCheck.validate(self.xmldoc)
+            self.parse_schema_and_doc()
+            schema_check = etree.XMLSchema(self.schemadoc)
+            valid = schema_check.validate(self.xmldoc)
         return valid
     
-    def findInvalidXML(self):
+    def find_invalid_xml(self):
         """
         Finds the first offending element that should not be present in XML file
         """
-        firstError = ""
-        self.parseSchemaAndDoc()
+        first_error = ""
+        self.parse_schema_and_doc()
         schema = etree.XMLSchema(self.schemadoc)
         try:
-            firstError = schema.assertValid(self.xmldoc)
+            first_error = schema.assertValid(self.xmldoc)
         except etree.DocumentInvalid as e:
-            firstError = str(e)
-        return firstError
-    
-    def parseSchemaAndDoc(self):
+            first_error = str(e)
+        return first_error
+    
+    def parse_schema_and_doc(self):
         """
         Creates a dictionary of the parsed schema and xml files.
         """
-        self.setXMLFile(self.xml)
-        self.setSchema(self.schema)
-        
-    def toString(self, elem, pp=False, encoding=None):
+        self.set_xml_file(self.xml)
+        self.set_schema(self.schema)
+        
+    def to_string(self, elem, pp=False, encoding=None):
         """
         Converts an etree element into a string
@@ -129,5 +137,5 @@
         return dic
     
-    def setProcessingInstructions(self):
+    def set_processing_instructions(self):
         """
         Take out all processing instructions and create a dictionary from them
@@ -135,7 +143,7 @@
         """
         dic = {}
-        pi = self.xmlroot.getprevious()
-        while pi is not None:
-            pi_string = self.toString(pi)
+        proc_instr = self.xmlroot.getprevious()
+        while proc_instr is not None:
+            pi_string = self.to_string(proc_instr)
             if "?>\n<?" in pi_string:
                 pi_string = pi_string.split("?>\n<?")
@@ -145,11 +153,11 @@
                 for item in pi_string:
                     dic = self.break_processing_instructions(item, dic)
-            pi = pi.getprevious()
+            proc_instr = proc_instr.getprevious()
         if 'xml' in dic:
-            self.setEncoding(dic['xml'])
+            self.set_encoding(dic['xml'])
             del dic['xml']
-        self.processingInstructions = dic
-        
-    def setEncoding(self, attr_str):
+        self.processing_instructions = dic
+        
+    def set_encoding(self, attr_str):
         """
         Find the encoding in the xml declaration and save it as a string
@@ -169,5 +177,5 @@
         self.encoding = None
         
-    def _create_unique_key(self, dictionary, name, i = 0):
+    def _create_unique_key(self, dictionary, name, numb = 0):
         """
         Create a unique key value for any dictionary to prevent overwriting
@@ -176,11 +184,11 @@
         :param dictionary: A dictionary with any number of entries
         :param name: The index of the item to be added to dictionary
-        :param i: The number to be appended to the name, starts at 0
+        :param numb: The number to be appended to the name, starts at 0
         """
         if dictionary.get(name) is not None:
-            i += 1
+            numb += 1
             name = name.split("_")[0]
-            name += "_{0}".format(i)
-            name = self._create_unique_key(dictionary, name, i)
+            name += "_{0}".format(numb)
+            name = self._create_unique_key(dictionary, name, numb)
         return name
     
@@ -193,13 +201,13 @@
         return etree.ElementTree(root)
     
-    def create_element_from_string(self, s):
+    def create_element_from_string(self, xml_string):
         """
         Create an element from an XML string
         
-        :param s: A string of xml
-        """
-        return etree.fromstring(s)
-    
-    def create_element(self, name, attrib={}, nsmap=None):
+        :param xml_string: A string of xml
+        """
+        return etree.fromstring(xml_string)
+    
+    def create_element(self, name, attrib=None, nsmap=None):
         """
         Create an XML element for writing to file
@@ -207,4 +215,6 @@
         :param name: The name of the element to be created
         """
+        if attrib == None:
+            attrib = {}
         return etree.Element(name, attrib, nsmap)
     
@@ -237,8 +247,9 @@
         """
         pi_list = []
-        for key in self.processingInstructions:
-            value = self.processingInstructions.get(key)
-            pi = etree.ProcessingInstruction(key, value)
-            pi_list.append(pi)
+        if self.processing_instructions is not None:
+            for key in self.processing_instructions:
+                value = self.processing_instructions.get(key)
+                pi_item = etree.ProcessingInstruction(key, value)
+                pi_list.append(pi_item)
         return pi_list
     
@@ -253,6 +264,16 @@
         return tree
     
-    def ebuilder(self, parent, elementname, text=None, attrib={}):
+    def ebuilder(self, parent, elementname, text=None, attrib=None):
+        """
+        Use lxml E builder class with arbitrary inputs.
+        
+        :param parnet: The parent element to append a child to
+        :param elementname: The name of the child in string form
+        :param text: The element text
+        :param attrib: A dictionary of attribute names to attribute values
+        """
         text = str(text)
+        if attrib == None:
+            attrib = {}
         elem = E(elementname, attrib, text)
         parent = parent.append(elem)
Index: src/sans/perspectives/fitting/pagestate.py
===================================================================
--- src/sans/perspectives/fitting/pagestate.py	(revision eddb6eca9b813af3dd1f8c272f767fec8e5252fa)
+++ src/sans/perspectives/fitting/pagestate.py	(revision ac5b69d317038c3025e6c4a3397e52b2a3012a79)
@@ -20,4 +20,5 @@
 
 import xml.dom.minidom
+from xml.dom.minidom import parseString
 from lxml import etree
 
@@ -672,10 +673,21 @@
             # We are appending to an existing document
             newdoc = doc
-            top_element = newdoc.createElement(FITTING_NODE_NAME)
+            try:
+                top_element = newdoc.createElement(FITTING_NODE_NAME)
+            except:
+                string = etree.tostring(doc, pretty_print=True)
+                newdoc = parseString(string)
+                top_element = newdoc.createElement(FITTING_NODE_NAME)
             if entry_node is None:
                 newdoc.documentElement.appendChild(top_element)
             else:
-                entry_node.appendChild(top_element)
-            
+                try:
+                    entry_node.appendChild(top_element)
+                except:
+                    node_name = entry_node.tag
+                    node_list = newdoc.getElementsByTagName(node_name)
+                    entry_node = node_list.item(0)
+                    entry_node.appendChild(top_element)
+                    
         attr = newdoc.createAttribute("version")
         attr.nodeValue = '1.0'
@@ -750,5 +762,5 @@
         for item in list_of_state_parameters:
             element = newdoc.createElement(item[0])
-            com = "self._toXML_helper(list=self.%s,"
+            com = "self._toXML_helper(thelist=self.%s,"
             com += " element=element, newdoc=newdoc)"
             exec com % item[1]
@@ -762,5 +774,5 @@
             return None
         else:
-            return newdoc.toprettyxml()
+            return newdoc
         
     def _fromXML_helper(self, node, list):
@@ -1252,4 +1264,5 @@
                 state = PageState()
                 state.fromXML(node=nodes[0])
+                
         except:
             logging.info("XML document does not contain fitting information.\n %s" % sys.exc_value)
@@ -1257,5 +1270,5 @@
         return state
       
-    def _parse_entry(self, dom):
+    def _parse_save_state_entry(self, dom):
         """
         Parse a SASentry
@@ -1268,5 +1281,22 @@
         node = dom.xpath('ns:data_class', namespaces={'ns': CANSAS_NS})
         if not node or node[0].text.lstrip().rstrip() != "Data2D":
-            return CansasReader._parse_entry(self, dom)
+            return_value, _ = self._parse_entry(dom)
+            numpy.trim_zeros(return_value.x)
+            numpy.trim_zeros(return_value.y)
+            numpy.trim_zeros(return_value.dy)
+            size_dx = return_value.dx.size
+            size_dxl = return_value.dxl.size
+            size_dxw = return_value.dxw.size
+            if size_dxl == 0 and size_dxw == 0:
+                return_value.dxl = None
+                return_value.dxw = None
+                numpy.trim_zeros(return_value.dx)
+            elif size_dx == 0:
+                return_value.dx = None
+                size_dx = size_dxl
+                numpy.trim_zeros(return_value.dxl)
+                numpy.trim_zeros(return_value.dxw)
+                            
+            return return_value, _
         
         #Parse 2D
@@ -1539,5 +1569,5 @@
                     for entry in entry_list:
                         try:
-                            sas_entry = self._parse_entry(entry)
+                            sas_entry, _ = self._parse_save_state_entry(entry)
                         except:
                             raise
@@ -1608,13 +1638,14 @@
         # Sanity check
         if self.cansas == True:
-            
             # Add fitting information to the XML document
             doc = self.write_toXML(datainfo, fitstate)
             # Write the XML document
-            fd = open(filename, 'w')
-            fd.write(doc.toprettyxml())
-            fd.close()
         else:
-            fitstate.toXML(file=filename)
+            doc = fitstate.toXML(file=filename)
+        
+        # Save the document no matter the type
+        fd = open(filename, 'w')
+        fd.write(doc.toprettyxml())
+        fd.close()
         
     def write_toXML(self, datainfo=None, state=None):
@@ -1638,5 +1669,5 @@
                 state.data.run = [str(state.data.name)]
                 state.data.run_name[0] = state.data.name
-   
+            
             if issubclass(state.data.__class__,
                           sans.dataloader.data_info.Data1D):
@@ -1648,6 +1679,6 @@
             
         if state is not None:
-            state.toXML(doc=doc, file=data.filename, entry_node=sasentry)
-            
+            doc = state.toXML(doc=doc, file=data.filename, entry_node=sasentry)
+        
         return doc
     
Index: test/sansdataloader/test/utest_cansas.py
===================================================================
--- test/sansdataloader/test/utest_cansas.py	(revision 2e3b055365667cec714d68e643c78a70e38b9f85)
+++ test/sansdataloader/test/utest_cansas.py	(revision ac5b69d317038c3025e6c4a3397e52b2a3012a79)
@@ -5,6 +5,4 @@
 warnings.simplefilter("ignore")
 
-import unittest
-import numpy
 import sans.dataloader.readers.cansas_reader as cansas
 from sans.dataloader.loader import Loader
@@ -12,5 +10,5 @@
 from sans.dataloader.readers.xml_reader import XMLreader
 from sans.dataloader.readers.cansas_reader import Reader
-from sans.dataloader.readers.cansas_constants import cansasConstants
+from sans.dataloader.readers.cansas_constants import CansasConstants
 
 import os
@@ -18,10 +16,13 @@
 import urllib2
 import StringIO
+import pylint as pylint
+import unittest
+import numpy
 
 from lxml import etree
 from xml.dom import minidom
  
-CANSAS_FORMAT = cansasConstants.CANSAS_FORMAT
-CANSAS_NS = cansasConstants.CANSAS_NS
+CANSAS_FORMAT = CansasConstants.CANSAS_FORMAT
+CANSAS_NS = CansasConstants.CANSAS_NS
     
 class cansas_reader(unittest.TestCase):
@@ -72,5 +73,5 @@
     def test_real_xml(self):
         reader = XMLreader(self.xml_valid, self.schema_1_0)
-        valid = reader.validateXML()
+        valid = reader.validate_xml()
         if valid:
             self.assertTrue(valid)
@@ -101,6 +102,6 @@
         filename = "isis_1_1_write_test.xml"
         xmlreader = XMLreader(self.isis_1_1, self.schema_1_1)
-        valid = xmlreader.validateXML()
-        xmlreader.setProcessingInstructions()
+        valid = xmlreader.validate_xml()
+        xmlreader.set_processing_instructions()
         self.assertTrue(valid)
         fo = open(self.isis_1_1)
@@ -126,5 +127,5 @@
     def test_double_trans_spectra(self):
         xmlreader = XMLreader(self.isis_1_1_doubletrans, self.schema_1_1)
-        self.assertTrue(xmlreader.validateXML())
+        self.assertTrue(xmlreader.validate_xml())
         reader = Loader()
         data = reader.load(self.isis_1_1_doubletrans)
@@ -146,30 +147,30 @@
         valid = []
         reader1 = XMLreader(self.xml_valid, self.schema_1_0)
-        self.assertTrue(reader1.validateXML())
+        self.assertTrue(reader1.validate_xml())
         reader2 = XMLreader(self.xml_invalid, self.schema_1_0)
-        self.assertFalse(reader2.validateXML())
+        self.assertFalse(reader2.validate_xml())
         reader3 = XMLreader(self.xml_valid, self.schema_1_1)
-        self.assertFalse(reader3.validateXML())
+        self.assertFalse(reader3.validate_xml())
         reader4 = XMLreader(self.xml_invalid, self.schema_1_1)
-        self.assertFalse(reader4.validateXML())
+        self.assertFalse(reader4.validate_xml())
         reader5 = XMLreader(self.isis_1_0, self.schema_1_0)
-        self.assertTrue(reader5.validateXML())
+        self.assertTrue(reader5.validate_xml())
         reader6 = XMLreader(self.isis_1_1, self.schema_1_1)
-        self.assertTrue(reader6.validateXML())
+        self.assertTrue(reader6.validate_xml())
         reader7 = XMLreader(self.isis_1_1, self.schema_1_0)
-        self.assertFalse(reader7.validateXML())
+        self.assertFalse(reader7.validate_xml())
         
        
     def test_old_cansas_files(self):
         reader1 = XMLreader(self.cansas1d, self.schema_1_0)
-        self.assertTrue(reader1.validateXML())
+        self.assertTrue(reader1.validate_xml())
         file_loader = Loader()
         file1 = file_loader.load(self.cansas1d)
         reader2 = XMLreader(self.cansas1d_units, self.schema_1_0)
-        self.assertTrue(reader2.validateXML())
+        self.assertTrue(reader2.validate_xml())
         reader3 = XMLreader(self.cansas1d_badunits, self.schema_1_0)
-        self.assertTrue(reader3.validateXML())
+        self.assertTrue(reader3.validate_xml())
         reader4 = XMLreader(self.cansas1d_slit, self.schema_1_0)
-        self.assertTrue(reader4.validateXML())
+        self.assertTrue(reader4.validate_xml())
         
     
@@ -177,5 +178,5 @@
         filename = "isis_1_0_write_test.xml"
         xmlreader = XMLreader(self.isis_1_0, self.schema_1_0)
-        valid = xmlreader.validateXML()
+        valid = xmlreader.validate_xml()
         self.assertTrue(valid)
         reader_generic = Loader()
@@ -191,5 +192,5 @@
             written_data = return_data[0]
             xmlwrite = XMLreader(filename, self.schema_1_0)
-            valid = xmlreader.validateXML()
+            valid = xmlreader.validate_xml()
             self.assertTrue(valid)
             self._check_data(written_data)
@@ -198,8 +199,8 @@
     def test_processing_instructions(self):
         reader = XMLreader(self.isis_1_1, self.schema_1_1)
-        valid = reader.validateXML()
+        valid = reader.validate_xml()
         if valid:
             ## find the processing instructions and make into a dictionary
-            dic = self.getProcessingInstructions(reader)
+            dic = self.get_processing_instructions(reader)
             self.assertTrue(dic == {'xml-stylesheet': 'type="text/xsl" href="cansas1d.xsl" '})
             
@@ -208,19 +209,19 @@
             
             ## take the processing instructions and put them back in
-            xmldoc = self.setProcessingInstructions(xmldoc, dic)
+            xmldoc = self.set_processing_instructions(xmldoc, dic)
             xml_output = xmldoc.toprettyxml()
             
     
-    def setProcessingInstructions(self, minidomObject, dic):
-        xmlroot = minidomObject.firstChild
+    def set_processing_instructions(self, minidom_object, dic):
+        xmlroot = minidom_object.firstChild
         for item in dic:
-            pi = minidomObject.createProcessingInstruction(item, dic[item])
-            minidomObject.insertBefore(pi, xmlroot)
-        return minidomObject
-    
-    
-    def getProcessingInstructions(self, XMLreaderObject):
+            pi = minidom_object.createProcessingInstruction(item, dic[item])
+            minidom_object.insertBefore(pi, xmlroot)
+        return minidom_object
+    
+    
+    def get_processing_instructions(self, xml_reader_object):
         dict = {}
-        pi = XMLreaderObject.xmlroot.getprevious()
+        pi = xml_reader_object.xmlroot.getprevious()
         i = 0
         while pi is not None:
