2013-07-10 76 views
0

我讀一個XML文件SAX跳過DOCTYPE

但是,我似乎無法找出辦法讓它跳過以下行

<!DOCTYPE POWERMART SYSTEM "powrmart.dtd"> 

我得到的錯誤:

File "C:\Python33\lib\urllib\request.py", line 280, in _parse 
raise ValueError("unknown url type: %r" % self.full_url) 
ValueError: unknown url type: '../procesar rules/powrmart.dtd' 

有誰知道如何處理異常或跳過這一行與薩克斯?

回答

0

試試這個

fp = open("file_name","r") 
    fp2 = open("file_name_temp","w+") 
    for line in fp: 
     if (line.find("DOCTYPE")<0): 
      fp2.writelines(line) 
    fp.close() 
    fp2.close()