[英]How to handle libxml2 parserError exception with python
我嘗試編寫使用xsl樣式表解析xml文件並將其轉換為html的warpper。 對於損壞的xml輸入文件,我得到了異常:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python27\lib\lib-tk\Tkinter.py", line 1410, in __call__
return self.func(*args)
File "C:\Users\USER\Desktop\raportowanie\topsurv raport_beta01\_newest\transmutation for trimble\testing_transmutation_v.0.6.2.py", line 712, in btnConvertClick
doc = libxml2.parseFile(filename)
File "C:\Python27\lib\site-packages\libxml2.py", line 1279, in parseFile
if ret is None:raise parserError('xmlParseFile() failed')
parserError: xmlParseFile() failed
並嘗試沒有成功:
try:
doc = libxml2.parseFile(filename)
except (libxml2.parserError, TypeError):
print 'error'
實際上,我沒有任何異常,解析器的行為就像成功一樣。
我想請您幫忙。
我建議使用BeautifulSoup,因為它能夠解析格式錯誤的xml。
實際上,功能列表中的第一個是:
如果您給它不好的評分,美麗的湯不會cho。 它產生的解析樹的意義與原始文檔差不多。 通常,這足以收集所需的數據並使其消失。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.