Что нового

[Массивы] Как правильно вытащить данные из XML файла

alex33

Скриптер
Сообщения
1,457
Репутация
186
Пример как можно вытащить данные из xml функцией _StringBetween
Показывает пароли от FTP-клиента Filezilla
Код:
#include <GUIConstants.au3>
#include <ListViewConstants.au3>
#include <String.au3>
$filepath = @AppDataDir&"\FileZilla\sitemanager.xml"
If Not FileExists($filepath) Then
MsgBox(16, "Xml parser error", "File not exists")
Exit
EndIf
$filecontent = FileRead($filepath)
If StringInStr($filecontent, "<?xml") <> 1 Then
MsgBox(16, "Xml parser error", "File not validation")
Exit
EndIf
$host = _StringBetween($filecontent, "<Host>", "</Host>")
$user = _StringBetween($filecontent, "<User>", "</User>")
$pass = _StringBetween($filecontent, "<Pass>", "</Pass>")
Global $t_e = FileGetTime($filepath, 0, 1)
$title = "Xml parser"
Opt("GUICloseOnEsc", 0)
$gui = GUICreate($title, 400, 400, 20, 20)
$label1 = GUICtrlCreateLabel("site manager list", 10, 10, 100, 30)
$listview1 = GUICtrlCreateListView("Host|User|Password", 10, 50, 300, 330)
$size = UBound($host)-1
For $i = 0 To $size
GUICtrlCreateListViewItem($host[$i]&"|"&$user[$i]&"|"&$pass[$i], $listview1)
Next
GUICtrlSendMsg($listview1, $LVM_SETCOLUMNWIDTH, 0, -1)
GUISetState(@SW_SHOW, $gui)
AdlibRegister("_Update_listview1_data", 5000)
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
AdlibUnRegister("_Update_listview1_data")
ExitLoop
EndSwitch
WEnd
GUIDelete($gui)
Func _Update_listview1_data()
$t = FileGetTime($filepath, 0, 1)
If $t_e <> $t Then
$filecontent = FileRead($filepath)
If StringInStr($filecontent, "<?xml") <> 1 Then
Return 0
EndIf
$host = _StringBetween($filecontent, "<Host>", "</Host>")
$user = _StringBetween($filecontent, "<User>", "</User>")
$pass = _StringBetween($filecontent, "<Pass>", "</Pass>")
$t_e = FileGetTime($filepath, 0, 1)
GUICtrlSendMsg($listview1, $LVM_Deleteallitems, 0, 0)
$size = UBound($host)-1
For $i = 0 To $size
GUICtrlCreateListViewItem($host[$i]&"|"&$user[$i]&"|"&$pass[$i], $listview1)
Next
GUICtrlSendMsg($listview1, $LVM_SETCOLUMNWIDTH, 0, -1)
Return 1
EndIf
Return 0
EndFunc
Посмотреть скрин
 
Верх