¡¾ÇóÖú¡¿python xmlÎļþ¶ÁÈ¡ºÍת»»ÎÊÌâ
#½«GB2312¸ñʽתΪUTF-8¸ñʽ
f = codecs.open('e:\TestResult.xml', "rb", "gb2312")
text = f.read().encode("utf-8")
f.close
f = open(options.TestResultFile, "wb")
f.write(text)
f.close()
Ìáʾ File "E:\TOOLS\ICP\ICP-23\cruisecontrol\userData\groups\group01\projects\R12ProductTest\script\pyt
hon_script\StaticResult.py", line 29, in main
text = f.read().encode("utf-8")
File "C:\Python25\lib\codecs.py", line 606, in read
return self.reader.read(size)
UnicodeDecodeError: 'gb2312' codec can't decode bytes in position 55-56: illegal multibyte sequence
ÊÇf.read()³öÁËÎÊÌ⣬ÒòΪ¡£encode("utf-8") È¥µôÈÔÈ»ÊǸÃÏÖÏó¡£
²»ÖªµÀÎÒÕâÀï¶ÁÈ¡ÓкÎÎÊÌ⣿
ÕâÊdzÉÊìµÄ²úÆ·´úÂ룬ÒѾÓбðÈËÔÚʹÓ᣶øÇÒÎÒʹÓÃËûÃÇͬÑùµÄÎļþÀ´²Ù×÷£¬ÒÔ¼°Í¬ÑùµÄpython°æ±¾£¨2.5£©Ò²ÊÇÕâÑùµÄÎÊÌ⣬ºÃÆæ¹Ö£¡
¶ÔÁË£¬ÍüÁË open
Python code:
def _openAnything(self, source):
try:
f = urllib.urlopen(source)
data = f.read()
Ïà¹ØÎÊ´ð£º
txt ºÍXML ¸ñʽÏàÓ¦
²»½èÖúDataSet
µ¼Èë¶ÁÈ¡TXTÎļþ
È»ºóÖ±½ÓдÈëXML(ͬһÎļþ,²»Í¬Êý¾Ý,µÝÔöÔÊý¾ÝûÓб»¸²¸ÇÇé¿öÏÂÔö¼ÓÊý¾Ý.)
½Ì¸öÒªµã»ò×îºÃÊÇÓиö´úÂëÌáʾµÄ
¹ý·ºÃºº °ï¸öæÈö^^
²»»á£¬°ïÂ¥Ö÷ ......
Êý¾Ý¿â±íÖÐÓÐÒ»ÁУ¨TranXml£©ÀàÐÍÊÇxml£¬´æ´¢µÄÊÇÀàËÆ
<fathernode>
<a>aaa
</a>
<b>bbb
</b>
</fathernode>
µÄÐÅÏ¢£¬²¢ÇÒͨ¹ý²éѯ·½· ......
ÎÒÔÚ±àдһ¸öwince5.0µÄ³ÌÐò£¬ÏëʵÏÖ°ÑPDAÉϵÄÒ»¸öLIST <STRING>ÀàÐ͵ÄÊý¾ÝÐòÁл¯ÎªXML£¬È»ºóÔÚPCÉϵÄÒ»¸öwebserviceÄõ½Õâ¸öXML£¬×ª»¯ÎªDataset£¬¸üÐÂPCÉϵÄÊý¾Ý¿â£¬ÎÒÏëÎÊÔõô°ÑXML´«¸øwebserviceµÄÄØ£¿
......
ÎÒÓÐÒ»¸öXML.ÏëÈ¡
<Portfolio _Name="XXXX" _Id="AUD" >
ÖеÄÊôÐÔ_IdµÄÖµ.µ«ÊÇÓÃÏÂÃæµÄÓï¾äºÃÏó²»ÐÐ.
XmlNode CId = xdoc_Msg.SelectSingleNode("/Portfolio");
&n ......