怪异,读取带有中文的xml失败。
xml文件如下,如果把里面的中文去掉,代码很完美的执行,没有一丝遗漏。一旦任何一个值改成中文,死活也读不出来了。。。莫非是编码问题?<DiskSet>
<Disk>
<DiskID>303</DiskID>
<FileSize>1024</FileSize>
<LockMemory>0</LockMemory>
<DiskState>4</DiskState>
<ManagerVersionID>0</ManagerVersionID>
<ManagerIP>0</ManagerIP>
<VTYear>2011</VTYear>
<VTMonth>12</VTMonth>
<VTDay>3</VTDay>
<VTHour>12</VTHour>
<VTMinute>25</VTMinute>
<VTSecond>36</VTSecond>
<VTMilliseconds>906</VTMilliseconds>
<DiskName>SYS</DiskName>
<DiskPath>E:\Image\SYS\T201112031225360890.img</DiskPath>
<VersionPath>E:\Image\SYS\T201112031225360890.xml</VersionPath>
</Disk>
<Disk>
<DiskID>测试</DiskID>
<FileSize>1024</FileSize>
<LockMemory>0</LockMemory>
<DiskState>4</DiskState>
<ManagerVersionID>0</ManagerVersionID>
<ManagerIP>0</ManagerIP>
<VTYear>2011</VTYear>
<VTMonth>12</VTMonth>
<VTDay>3</VTDay>
<VTHour>18</VTHour>
<VTMinute>19</VTMinute>
<VTSecond>58</VTSecond>
<VTMilliseconds>875</VTMilliseconds>
<DiskName>ss</DiskName>
<DiskPath>E:\Image\Test1\T201112031819580750.img</DiskPath>
<VersionPath>E:\Image\Test1\T201112031819580750.xml</VersionPath>
</Disk>
</DiskSet>
代码如下。#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$strSourceFile = 'Test.xml'
$Form1 = GUICreate("窗体1", 444, 304, 392, 277)
$ListView1 = GUICtrlCreateListView("编号|大小|状态|名字|路径", 8, 8, 425, 257)
$Button1 = GUICtrlCreateButton("Exit", 360, 272, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
R_xml()
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE, $Button1
$objDoc = 0
Exit
EndSwitch
WEnd
Func R_xml()
$objXML = ObjCreate("Microsoft.XMLDOM")
$sFile = $objXML.load($strSourceFile)
If Not $sFile Then
MsgBox(16, '', "加载" & $strSourceFile & "失败,文件不存在!!!")
Else
$objRootsite = $objXML.documentElement.selectSingleNode("//DiskSet")
$AllNodesNum = $objRootsite.childNodes.length
If $AllNodesNum < 0 Then
MsgBox(0, '', '没有镜像文件')
Else
Local $temp
For $i = 0 To $AllNodesNum - 1
$DiskID = $objRootsite.childNodes.item($i).childNodes.item(0).text
$DiskSize = $objRootsite.childNodes.item($i).childNodes.item(1).text
$DiskState = $objRootsite.childNodes.item($i).childNodes.item(3).text
$DiskName = $objRootsite.childNodes.item($i).childNodes.item(13).text
$DiskPath = $objRootsite.childNodes.item($i).childNodes.item(14).text
GUICtrlCreateListViewItem($DiskID & '|' & $DiskSize & '|' & $DiskState & '|' & _
$DiskName & '|' & $DiskPath, $ListView1)
Next
EndIf
EndIf
EndFunc ;==>R_xml
把xml的编码存为UTF-8就能读取中文了,这是为啥俺不知道……
页:
[1]