Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/345.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python元素树xml内容作为字符串_Python_Xml_Elementtree_Minidom - Fatal编程技术网

Python元素树xml内容作为字符串

Python元素树xml内容作为字符串,python,xml,elementtree,minidom,Python,Xml,Elementtree,Minidom,我需要解析xml,并将整个内容捕获到字符串中。我试着使用minidom,它是可以做到的。请通过ElementTree帮助实现这一点 XML: 但是,当我使用it ElementTree进行操作时,我不确定如何实现这一点:我的代码到目前为止 import xml.etree.ElementTree as etree tree = etree.parse('C:\\Users\\Administrator\\Desktop\\country.xml') print tree.getroot()

我需要解析xml,并将整个内容捕获到字符串中。我试着使用minidom,它是可以做到的。请通过ElementTree帮助实现这一点

XML:

但是,当我使用it ElementTree进行操作时,我不确定如何实现这一点:我的代码到目前为止

 import xml.etree.ElementTree as etree
 tree = etree.parse('C:\\Users\\Administrator\\Desktop\\country.xml')
 print tree.getroot() *This is not working*
可以使用从ElementTree生成字符串:

print etree.tostring(tree.getroot())
 import xml.etree.ElementTree as etree
 tree = etree.parse('C:\\Users\\Administrator\\Desktop\\country.xml')
 print tree.getroot() *This is not working*
print etree.tostring(tree.getroot())