Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.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_Lxml_Xml Namespaces_Elementtree - Fatal编程技术网

在python中创建xml文件时删除命名空间前缀

在python中创建xml文件时删除命名空间前缀,python,xml,lxml,xml-namespaces,elementtree,Python,Xml,Lxml,Xml Namespaces,Elementtree,我正在用python创建一个XML文件。 第一个元素构建如下: xsi = "http://www.w3.org/2001/XMLSchema-instance" mainElement = ET.Element("{" +xsi+ "}ArrayOfAnyType") 其结果是一行: <xsi:ArrayOfAnyType xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 我无法解决的是如何删除“xsi:Array

我正在用python创建一个XML文件。 第一个元素构建如下:

xsi = "http://www.w3.org/2001/XMLSchema-instance"
mainElement = ET.Element("{" +xsi+ "}ArrayOfAnyType")
其结果是一行:

<xsi:ArrayOfAnyType xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

我无法解决的是如何删除“xsi:Array…”中的xsi前缀。 创建的xml文件的其余部分正是我所需要的

谢谢你的提示


Piotr

您想要这样的字符串:
?完全正确。这就是我想要的。要添加更多信息,我不能使用ET.tostring,所以我不能用空字符串替换前缀。我想在ET.元素创建中找到一些解决方案。试试看,你想要这样的字符串:
?正是这样。这就是我想要的。要添加更多信息,我不能使用ET.tostring,所以我不能用空字符串替换前缀。我宁愿在ET中考虑一些解决方案。元素创建。尝试,它是