# $Id: test_parse.py 3298 2007-09-13 14:38:02Z fredrik $ from support import * def parsefile(): """ Test parsing from file. >>> tree = ET.parse("samples/simple.xml") >>> normalize_crlf(tree) >>> tree.write(sys.stdout) text texttail >>> tree = ET.parse("samples/simple-ns.xml") >>> normalize_crlf(tree) >>> tree.write(sys.stdout) text texttail """ def parseliteral(): r""" >>> element = ET.XML("text") >>> ET.ElementTree(element).write(sys.stdout) text >>> element = ET.fromstring("text") >>> ET.ElementTree(element).write(sys.stdout) text >>> sequence = ["", "text"] >>> element = ET.fromstringlist(sequence) >>> ET.ElementTree(element).write(sys.stdout) text >>> print ET.tostring(element) text >>> print "".join(ET.tostringlist(element)) text >>> print ET.tostring(element, "ascii") text >>> _, ids = ET.XMLID("text") >>> len(ids) 0 >>> _, ids = ET.XMLID("text") >>> len(ids) 1 >>> ids["body"].tag 'body' """ def error(xml): """ Test error handling. >>> error("foo").position (1, 0) >>> error("&foo;").position (1, 5) >>> error("foobar<").position (1, 6) """ try: ET.XML(xml) except ET.ParseError: return sys.exc_value