回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>我对minidom解析器处理空元素感到困惑,如下代码部分所示。</p>
<pre><code>import xml.dom.minidom
doc = xml.dom.minidom.parseString('<value></value>')
print doc.firstChild.nodeValue.__repr__()
# Out: None
print doc.firstChild.toxml()
# Out: <value/>
doc = xml.dom.minidom.Document()
v = doc.<a href="https://www.cnpython.com/list/append" class="inner-link">append</a>Child(doc.createElement('value'))
v.appendChild(doc.createTextNode(''))
print v.firstChild.nodeValue.__repr__()
# Out: ''
print doc.firstChild.toxml()
# Out: <value></value>
</code></pre>
<p>我怎样才能得到一致的行为?我想接收<em>空字符串</em>作为<em>空元素</em>的值(这<em>首先是</em>我放在XML结构中的值)。</p>