Python 创建XML文件解析文本文件//XML.etree.ElementTree不工作

Python 创建XML文件解析文本文件//XML.etree.ElementTree不工作,python,xml,parsing,Python,Xml,Parsing,我正在尝试将文本文件中的数据组织成XML文件,用XML标记器标记文本中要标记的部分 这个问题。 xml.etree.ElementTree无法识别该字符串 到目前为止,该代码仍然有效 import xml.etree.ElementTree as ET with open('input/application_EN.txt', 'r') as f: application_text=f.read() 我想做的第一件事是标记段落。文本应如下所示: <description>

我正在尝试将文本文件中的数据组织成XML文件,用XML标记器标记文本中要标记的部分

这个问题。 xml.etree.ElementTree无法识别该字符串

到目前为止,该代码仍然有效

import xml.etree.ElementTree as ET
with open('input/application_EN.txt', 'r') as f:
    application_text=f.read()
我想做的第一件事是标记段落。文本应如下所示:

<description>
    <paragraph id=1>
           blabla
    </paragraph>
    <paragraph id=2>
          blabla
    </paragraph>
        ...
</description>
正如你在结尾看到的,有一个符号“&Co”,它会引起麻烦

来自:

一些字符在XML中有特殊的含义,符号(&)就是其中之一。因此,应使用各自的实体引用替换这些字符(即使用字符串替换)。根据XML规范,XML中有5个预定义实体:

&lt;    <   less than
&gt;    >   greater than
&amp;   &   ampersand 
&apos;  '   apostrophe
&quot;  "   quotation mark
<
>大于
&;&符号
&apos;'撇号
“”引号

感谢@fallereneaper为我指点BS来创建XML文件

你调查过吗?没有。读一读。但是你的意思是为了创建XML文件,使用BS?如果您正在创建,可以使用BS,然后将其转储到文件中。如果您正在阅读,您可以加载一个文件,然后相应地查询它。我在你的帖子中没有看到任何关于&的信息,所以你需要向我们提供样本数据,以帮助我们了解细节though@fallenreaper但您的意思是可以使用BS将文本转储到XML格式的文件中?对
application_text='Language=English
Has all kind of kind of references. also measures.

Photovoltaic solar cells for directly converting radiant energy from the sun into electrical energy are well known. The manufacture of photovoltaic solar cells involves provision of semiconductor substrates in the form of sheets or wafers having a shallow p-n junction adjacent one surface thereof (commonly called the "front surface"). Such substrates may include an insulating anti-reflection ("AR") coating on their front surfaces, and are sometimes referred to as "solar cell wafers". The anti-reflection coating is transparent to solar radiation. In the case of silicon solar cells, the AR coating is often made of silicon nitride or an oxide of silicon or titanium. Such solar cells are manufactured and sold by E.I. duPont de Nemeurs & Co.'
&lt;    <   less than
&gt;    >   greater than
&amp;   &   ampersand 
&apos;  '   apostrophe
&quot;  "   quotation mark