我们从Python开源项目中,提取了以下6个代码示例,用于说明如何使用xml.etree.ElementTree.fromstringlist()。
def parseliteral(): """ >>> element = ET.XML("<html><body>text</body></html>") >>> ET.ElementTree(element).write(sys.stdout, encoding='unicode') <html><body>text</body></html> >>> element = ET.fromstring("<html><body>text</body></html>") >>> ET.ElementTree(element).write(sys.stdout, encoding='unicode') <html><body>text</body></html> >>> sequence = ["<html><body>", "text</bo", "dy></html>"] >>> element = ET.fromstringlist(sequence) >>> ET.tostring(element) b'<html><body>text</body></html>' >>> b"".join(ET.tostringlist(element)) b'<html><body>text</body></html>' >>> ET.tostring(element, "ascii") b"<?xml version='1.0' encoding='ascii'?>\\n<html><body>text</body></html>" >>> _, ids = ET.XMLID("<html><body>text</body></html>") >>> len(ids) 0 >>> _, ids = ET.XMLID("<html><body id='body'>text</body></html>") >>> len(ids) 1 >>> ids["body"].tag 'body' """
def parseliteral(): """ >>> element = ET.XML("<html><body>text</body></html>") >>> ET.ElementTree(element).write(sys.stdout) <html><body>text</body></html> >>> element = ET.fromstring("<html><body>text</body></html>") >>> ET.ElementTree(element).write(sys.stdout) <html><body>text</body></html> >>> sequence = ["<html><body>", "text</bo", "dy></html>"] >>> element = ET.fromstringlist(sequence) >>> print ET.tostring(element) <html><body>text</body></html> >>> print "".join(ET.tostringlist(element)) <html><body>text</body></html> >>> ET.tostring(element, "ascii") "<?xml version='1.0' encoding='ascii'?>\\n<html><body>text</body></html>" >>> _, ids = ET.XMLID("<html><body>text</body></html>") >>> len(ids) 0 >>> _, ids = ET.XMLID("<html><body id='body'>text</body></html>") >>> len(ids) 1 >>> ids["body"].tag 'body' """
def get_resource_body(self): if self.res is not None: import xml.etree.ElementTree as ElementTree try: root_element = ElementTree.fromstringlist(self.res.content) if root_element.tag == 'message': return root_element.text except ET.ParseError: return self.res.content else: return None