0

私は次のxmlを持っています:

<Earth>
 <country name="Česká republika" population="8900000">
    <capital>Praha1</capital>        
  </country>
</Earth>

しかし、解析しようとすると、エラーで失敗します。

 xml.etree.ElementTree.ParseError: not well-formed (invalid token): line 2, column 20

私のコード:

 tree=etree.parse(input) # input -> file.xml
4

1 に答える 1

1

arhimmel が指摘したように、この問題はエンコードの問題である可能性があります。etree.parse では、ファイルのようなオブジェクトとパスを渡すことができるためimport codecs、コードの先頭に追加してから に置き換えることinputができますcodecs.open("file.xml", encoding="UTF-8")

于 2012-05-03T07:45:45.227 に答える