Skip to content

Commit

Permalink
Try different xml encoding when reading code data.
Browse files Browse the repository at this point in the history
  • Loading branch information
league1991 committed May 12, 2017
1 parent a30e824 commit 7992a89
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions CodeViewPy/db/DoxygenDB.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,24 @@ def _getXmlDocumentItem(self, fileName):
xmlDoc = self.xmlCache.get(filePath)
if xmlDoc:
return xmlDoc
try:
doc = ET.parse(filePath)
except:
traceback.print_exc()
doc = None

# try different encoding and configurations
encodingArray = ['utf-8', 'iso-8859-5']
for docEncoding in encodingArray:
try:
doc = ET.parse(filePath, parser=ET.XMLParser(encoding=docEncoding))
if doc is not None:
print('parse %s success. encoding = %s' % (fileName, docEncoding))
break
except:
print('parse %s failed. encoding = %s'% (fileName, docEncoding))
# traceback.print_exc()
continue
if doc is None:
print('parse %s failed'% (fileName, ))
return XmlDocItem(None)

xmlDoc = XmlDocItem(doc)
self.xmlCache[filePath] = xmlDoc
return xmlDoc
Expand Down Expand Up @@ -505,7 +518,7 @@ def _parseLocationDict(self, element):
if bodyEnd < 0:
bodyEnd = bodyStart

return {'file': bodyFile, 'line': bodyStart, 'column': 0, 'CountLine': bodyEnd - bodyStart,
return {'file': bodyFile, 'line': bodyStart, 'column': 0, 'CountLine': max(bodyEnd - bodyStart, 0),
'declLine': declLine, 'declColumn': declColumn, 'declFile': declFile}

def _parseEntity(self, element):
Expand Down

0 comments on commit 7992a89

Please sign in to comment.