擅长:python、mysql、java
<p>XML字符串开头有一个新行,请将其删除:</p>
<pre><code>xmlExample = """<?xml version="1.0"?>
...
</code></pre>
<p>或者,您可以只<code>strip()</code>XML字符串:</p>
<pre><code>source = io.StringIO(xmlExample.strip())
</code></pre>
<p>另外,您不必创建类似文件的缓冲区,而是使用<a href="https://docs.python.org/2/library/xml.etree.elementtree.html#xml.etree.ElementTree.fromstring" rel="noreferrer">^{<cd2>}</a>:</p>
<pre><code>root = ET.fromstring(xmlExample)
</code></pre>