# Path: pyxform/xform_instance_parser.py
# def parse_xform_instance(xml_str):
#     parser = XFormInstanceParser(xml_str)
#     return parser.get_flat_dict_with_attributes()


from pyxform.xform_instance_parser import parse_xform_instance
        import os.path
        return {"node_name": self._name, "id": self._id, "children": children}

    def to_xml(self):
        """
        A horrible way to do this, but it works (until we need the attributes
         pumped out in order, etc)
        """
        open_str = """<?xml version='1.0' ?><%s id="%s">""" % (self._name, self._id)
        close_str = """</%s>""" % self._name
        vals = ""
        for k, v in self._answers.items():
            vals += "<%s>%s</%s>" % (k, str(v), k)

        output = open_str + vals + close_str
        return output

    def answers(self):
        """
        This returns "_answers", which is a dict with the key-value
        responses for this given instance. This could be pumped to xml
        or returned as a dict for maximum convenience (i.e. testing.)
        """
        return self._answers

    def import_from_xml(self, xml_string_or_filename):

        if os.path.isfile(xml_string_or_filename):
            xml_str = open(xml_string_or_filename).read()
        else:
            xml_str = xml_string_or_filename

# Path: pyxform/xform_instance_parser.py
# def parse_xform_instance(xml_str):
#     parser = XFormInstanceParser(xml_str)
#     return parser.get_flat_dict_with_attributes()


# Path: pyxform/instance.py
from pyxform.xform_instance_parser import parse_xform_instance
        import os.path

        return {"node_name": self._name, "id": self._id, "children": children}

    def to_xml(self):
        """
        A horrible way to do this, but it works (until we need the attributes
         pumped out in order, etc)
        """
        open_str = """<?xml version='1.0' ?><%s id="%s">""" % (self._name, self._id)
        close_str = """</%s>""" % self._name
        vals = ""
        for k, v in self._answers.items():
            vals += "<%s>%s</%s>" % (k, str(v), k)

        output = open_str + vals + close_str
        return output

    def answers(self):
        """
        This returns "_answers", which is a dict with the key-value
        responses for this given instance. This could be pumped to xml
        or returned as a dict for maximum convenience (i.e. testing.)
        """
        return self._answers

    def import_from_xml(self, xml_string_or_filename):

        if os.path.isfile(xml_string_or_filename):
            xml_str = open(xml_string_or_filename).read()
        else:
            xml_str = xml_string_or_filename

        key_val_dict = parse_xform_instance(xml_str)