tr.findmeld('td1').content(name) tr.findmeld('td2').content(desc) foo = clone.write_htmlstring() def profile(num): ## import cProfile ## profiler = cProfile profiler.run("[run(root) for x in range(0,100)]", 'logfile.dat') stats = pstats.Stats('logfile.dat') stats.strip_dirs() stats.sort_stats('cumulative', 'calls') #stats.sort_stats('calls') stats.print_stats(num) if __name__ == '__main__': root = meld3.parse_xmlstring(template) run(root) profile(30) import timeit t = timeit.Timer("run(root)", "from __main__ import run, root") repeat = 50 number = 50 result = t.repeat(repeat, number) best = min(result) print "%d loops " % repeat usec = best * 1e6 / number msec = usec / 1000 print "best of %d: %.*g msec per loop" % (repeat, 8, msec) #run(root, trace=True)
<td meld:id="td2">Description</td> </tr> </tbody> </table> <input type="submit" name="next" value=" Next "/> </form> </div> </body> </html> """ from meld3 import parse_xmlstring from meld3 import parse_htmlstring from StringIO import StringIO import sys root = parse_xmlstring(xml) root.findmeld('title').content('My document') root.findmeld('form1').attributes(action='./handler') data = ( {'name':'Boys', 'description':'Ugly'}, {'name':'Girls', 'description':'Pretty'}, ) iterator = root.findmeld('tr').repeat(data) for element, item in iterator: element.findmeld('td1').content(item['name']) element.findmeld('td2').content(item['description']) root.write_xhtml(sys.stdout)