¡¾ÇóÖú¡¿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()
Ïà¹ØÎÊ´ð£º
Êý¾Ý¿â±íÖÐÓÐÒ»ÁУ¨TranXml£©ÀàÐÍÊÇxml£¬´æ´¢µÄÊÇÀàËÆ
<fathernode>
<a>aaa
</a>
<b>bbb
</b>
</fathernode>
µÄÐÅÏ¢£¬²¢ÇÒͨ¹ý²éѯ·½· ......
DataSetµ¼³öxml Åú´¦Àí(Ñ»·)µÃÔõô´¦Àí
XMLÎļþ
<A>
<B>
<C>
</C>
&nb ......
´ÓÊý¾Ý¿âÖвéѯһÕűíµÄÊý¾Ý
select ²¿ÃÅ,ÐÕÃû from tb
ÈçºÎ²ÅÄÜÉú³ÉÏÂÃæµÄxml¸ñʽ
XML code:
<folder state="unchecked" label="È«²¿">
¡¡¡¡ <folder state="unchecked&qu ......
²ÉÓÃDOM ½øÐнâÎöxml¡£ÒªÇó½«xml×Ö´®²åÈëÖ¸¶¨½Úµã×÷ΪÆä×Ó½Úµã
±ÈÈ磺
Ôxml
<root>
</root>
Òª²åÈëµÄxml×Ö´®
<a>test</a>
Ä¿µÄxml£º
<root>
<a> ......