BaseTools:The BOM character is processed when python reads a file
authorFan, ZhijuX <zhijux.fan@intel.com>
Tue, 26 Feb 2019 06:57:44 +0000 (14:57 +0800)
committerFeng, Bob C <bob.c.feng@intel.com>
Wed, 27 Feb 2019 01:39:09 +0000 (09:39 +0800)
When python3 reads an XML file it will parse the file in error
if the file has a BOM

Cc: Bob Feng <bob.c.feng@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Zhiju.Fan <zhijux.fan@intel.com>
Reviewed-by: Bob Feng <bob.c.feng@intel.com>
BaseTools/Source/Python/Ecc/Xml/XmlRoutines.py

index 4294016..00cbc4e 100644 (file)
@@ -17,6 +17,7 @@
 #\r
 from __future__ import print_function\r
 import xml.dom.minidom\r
+import codecs\r
 from Common.LongFilePathSupport import OpenLongFilePath as open\r
 \r
 ## Create a element of XML\r
@@ -211,7 +212,7 @@ def XmlNodeName(Dom):
 #\r
 def XmlParseFile(FileName):\r
     try:\r
-        XmlFile = open(FileName)\r
+        XmlFile = codecs.open(FileName,encoding='utf_8_sig')\r
         Dom = xml.dom.minidom.parse(XmlFile)\r
         XmlFile.close()\r
         return Dom\r