How to update value from XML? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
divaox

How to update value from XML?

18 Apr 2018, 13:22

I know how to read xml, but I cannot update XML Value. How can I do this?

Code: Select all

if FileExist("settings.xml")
{
	FileRead, xmldata, settings.xml
		
	xml := ComObjCreate("MSXML2.DOMDocument.6.0")
	xml.async := false
	xml.loadXML(xmldata)
	DocNode := xml.selectSingleNode("//Settings/SQLServer")
	
	DocNode.setValue("new value")
	test := DocNode.text
	MsgBox %test%
}
It's because DocNode.setValue("new value") is not working
conracer
Posts: 6
Joined: 26 Jul 2020, 11:51

Re: How to update value from XML?  Topic is solved

26 Jul 2020, 13:53

Code: Select all

configfile=
(
<?xml version="1.0" encoding="Windows-1252" ?>
<NotepadPlus>
    <GUIConfigs>
        <GUIConfig name="noUpdate" intervalDays="15" nextUpdateDate="20200808">no</GUIConfig>
        <GUIConfig name="Backup" action="0" useCustumDir="no" dir="" isSnapshotMode="yes" snapshotBackupTiming="7000" />
    </GUIConfigs>
</NotepadPlus>
)
; https://www.autohotkey.com/boards/viewtopic.php?f=5&t=47557
xmldata:=ComObjCreate("MSXML2.DOMDocument.6.0")
xmldata.async:=false
xmldata.loadXML(configfile)
; https://www.autohotkey.com/boards/viewtopic.php?t=3516
ids:=xmldata.selectNodes("//NotepadPlus/GUIConfigs/GUIConfig")
Loop % ids.length {
	if(ids.item(A_Index-1).getAttribute("name")="noUpdate")
		ids.item(A_Index-1).text:="yes"
	if(ids.item(A_Index-1).getAttribute("name")="Backup"&&ids.item(A_Index-1).getAttribute("isSnapshotMode")="yes")
		ids.item(A_Index-1).setAttribute("isSnapshotMode"):="no"
}
; MsgBox % xmldata.xml ; Note, that the String » encoding="Windows-1252"« is removed in this variable...
xmldata.save(A_Desktop "\a.xml") ; ...but luckily not in this line, so use "xmldata.save(% FILEPATH)" instead of maybe "FileAppend,% xmldata.xml,%A_Desktop%\a.xml"!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], JPMuir, sofista and 333 guests