Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/289.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.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_Rest - Fatal编程技术网

Python XML在浏览器上显示文档树

Python XML在浏览器上显示文档树,python,xml,rest,Python,Xml,Rest,大家好。我认为这是一个新手问题 如何使用python打印xml,就像浏览器屏幕截图显示的那样 谢谢大家! 试试这个: import xml.etree.ElementTree as ET import xml.dom.minidom parent_file_path = 'samplexml.xml' parent_tree = ET.parse(parent_file_path) parent = parent_tree.getroot() xmlstr = xml.dom.minidom.

大家好。我认为这是一个新手问题

如何使用python打印xml,就像浏览器屏幕截图显示的那样

谢谢大家!

试试这个:

import xml.etree.ElementTree as ET
import xml.dom.minidom

parent_file_path = 'samplexml.xml'
parent_tree = ET.parse(parent_file_path)
parent = parent_tree.getroot()
xmlstr = xml.dom.minidom.parseString(ET.tostring(parent)).toprettyxml()
print xmlstr

请出示你的代码,你做了什么,有什么问题,我们会帮助你;因此,不是免费编码服务,您可以使用
lxml
BeautifulSoup
配置为
xml
parser@Drako我通过
dicttoxml
将json转换为xml,然后返回xml作为响应。它只打印值,不打印标签。