def replace_elements(my, html_str): """ # NOTE: this likely is a better way to extract elements, but still # need to find a way to inject html back into the xml xml = Xml() xml.read_string("<div>%s</div>" % html_str) elements = xml.get_nodes("//element") for element in elements: # create a complete config full_line_str = xml.to_string(element) tmp_config = '''<config><tmp>%s</tmp></config>''' % full_line_str try: element_wdg = my.get_element_wdg(xml, my.def_config) element_html = element_wdg.get_buffer_display() except Exception, e: from pyasm.widget import ExceptionWdg element_html = ExceptionWdg(e).get_buffer_display() xml = Xml() try: xml.read_string(element_html) except Exception, e: print "Error: ", e xml.read_string("<h1>%s</h1>" % str(e) ) root = xml.get_root_node() parent = xml.get_parent(element) xml.replace_child(parent, element, root) return xml.to_string() """ # a simple readline interpreter html = Html() full_line = [] parse_context = None for line in html_str.split("\n"): line2 = line.strip() #if not parse_context and not line2.startswith('<element '): index = line2.find('<element>') if index == -1: index = line2.find('<element ') if not parse_context and index == -1: #line = Common.process_unicode_string(line) html.writeln(line) continue if index != -1: part1 = line2[:index] html.write(part1) line2 = line2[index:] full_line.append(line2) xml = Xml() # determine if this is valid xml try: # create a complete config full_line_str = "".join(full_line) tmp_config = '''<config><tmp>%s</tmp></config>''' % full_line_str xml.read_string(tmp_config, print_error=False) full_line = [] parse_context = '' except XmlException, e: parse_context = 'element' #raise e continue try: element_wdg = my.get_element_wdg(xml, my.def_config) if element_wdg: element_html = element_wdg.get_buffer_display() else: element_html = '' except Exception, e: from pyasm.widget import ExceptionWdg element_html = ExceptionWdg(e).get_buffer_display()