0

我在下面复制了一个名为“dictionary.xml”的 XML 文档。由于某种原因,该文档无法被 python 中的 XmlToDict 解析。

<dictmap>

<lexelt item="begin.v" num="4">
<sense id="1" wordnet="2,3,5,6,7" gloss="start, have an initial point " examples="Prices for these homes begin at $250,000 | The war began on a Thursday. | She began to feel sick. | When life began was there oxygen in the atmosphere? | The novel begins with a shipwreck at sea. | It's beginning to look like rain. | His property begins at the fence." />
<sense id="2" wordnet="1,8,5" gloss="initiate an undertaking" examples="They'll begin their tour with a concert in London. | You should begin the stew now so it will have four hours to simmer. | The government is beginning to protect the coral reefs of that island. | He was just beginning a novel when the phone rang. | Acme Tire Co. began offering their employees health insurance. | John has begun to take them seriously. | She began ballet at age four." />
<sense id="3" wordnet="4" gloss="make a locution, speak" examples=""now listen, friends", he began." />
<sense id="4" wordnet="9" gloss="partially attain" examples="The rent you could get for that place wouldn't begin to cover the mortgage and taxes. | Can those refugees even begin to hope they'll be granted asylum? | I couldn't begin to tell you all the ways she has contributed to this club." />
</lexelt>

<lexelt item="complain.v" num="2">
<sense id="1" wordnet="1" gloss="express feelings of pain, dissatisfaction, or resentment" examples="Lots of people have complained about the noise. | You're always complaining! | He complained that his boss was useless and he had too much work. | She's complaining about a headache." />
<sense id="2" wordnet="2" gloss="make formal, legal accusation or bring charge" examples="The neighbors complained to the police about the noise. | We have complained to the authorities and they will need to take action now. | The lawyer complained that the defendant had physically abused his client." />
</lexelt>


</dictmap>

以下代码应该可以工作,但会触发以下错误:

xmltodict.parse('dictionary.xml')

>>>>
---------------------------------------------------------------------------
ExpatError                                Traceback (most recent call last)
<ipython-input-16-c098f9f722f0> in <module>
----> 1 xmltodict.parse('dictionary.xml')

~/opt/anaconda3/lib/python3.7/site-packages/xmltodict.py in parse(xml_input, encoding, expat, process_namespaces, namespace_separator, disable_entities, **kwargs)
    325         parser.ParseFile(xml_input)
    326     else:
--> 327         parser.Parse(xml_input, True)
    328     return handler.item
    329 

ExpatError: syntax error: line 1, column 0

我需要做什么来纠正这个问题?

4

1 回答 1

0

更改引号

examples=""now listen, friends", he began."

examples="&quot;now listen, friends&quot;, he began."

如此处所述:如何在 XML 属性值中转义双引号?

于 2019-11-25T18:26:58.890 回答