|
发表于 2020-3-27 13:46:09
|
显示全部楼层
a大的正则方式不知是否满足你,下面是我的一个简单示例希望能帮到你
#include <WinAPIFiles.au3>
#include <GUIConstantsEx.au3>
#include <GuiEdit.au3>
#include <EditConstants.au3>
#include <FileConstants.au3>
Local $Poet = "" ;诗人
Local $PoemName = "" ;诗名
Local $Poetry = "" ;诗
#Region ;读取xml文件内容
Local $SourceFile = @WorkingDir & "\Test.xml"
Local $objXML = ObjCreate("Microsoft.XMLDOM")
Local $xFile = $objXML.load($SourceFile)
If Not $xFile Then
MsgBox(16, "错误", "加载" & $SourceFile & "失败,文件不存在!!!")
Exit
Else
Local $PoetryNode = $objXML.selectSingleNode("/root/poetry[@id='one']")
If $PoetryNode.attributes.length > 0 Then
$Poet = $PoetryNode.attributes.getNamedItem("poet").text
$PoemName = $PoetryNode.attributes.getNamedItem("poemname").text
$Poetry = $objXML.selectSingleNode("/root/poetry[@id='one']").text
Else
MsgBox(16, "提示信息", "没有内容")
EndIf
EndIf
#EndRegion ;读取xml文件内容
Local $hGUI = GUICreate("ReadOrWriteXML", 400, 300)
GUICtrlCreateLabel("诗名 :", 60, 10, 390, 20)
Local $InputPoemName = GUICtrlCreateInput($PoemName, 100, 10, 200, 20)
GUICtrlCreateLabel("作者 :", 60, 50, 390, 20)
Local $InputPoet = GUICtrlCreateInput($Poet, 100, 50, 200, 20)
GUICtrlCreateLabel("诗 :", 60, 100, 390, 20)
Local $EditPoetry = GUICtrlCreateEdit($Poetry, 100, 100, 200, 100)
Local $BtnSave=GUICtrlCreateButton("保存",100, 260, 200, 20)
GUISetState(@SW_SHOW, $hGUI)
While 1
Switch GUIGetMsg()
Case $BtnSave
SaveAccountPassword("Save")
Case $GUI_EVENT_CLOSE
ExitLoop
EndSwitch
WEnd
Func SaveAccountPassword($IsShow)
Local $PoetryNode = $objXML.selectSingleNode("/root/poetry[@id='one']")
$PoetryNode.attributes.getNamedItem("poet").text = GUICtrlRead($InputPoet)
$PoetryNode.attributes.getNamedItem("poemname").text = GUICtrlRead($InputPoemName)
$PoetryNode.text = GUICtrlRead($EditPoetry)
$objXML.Save($SourceFile)
If @error == 0 Then
MsgBox("-1", "提示信息", "保存成功", 10)
Else
MsgBox("-1", "提示信息", "保存失败", 10)
EndIf
EndFunc ;==>SaveAccountPassword
;xml文件格式
<?xml version="1.0"?>
<root>
<poetry id="one" poet="李白" poemname="静夜思">床前明月光,疑是地上霜。
举头望明月,低头思故乡。</poetry>
</root>
|
|