scanie Posted February 2, 2013 Share Posted February 2, 2013 I'm trying to create a script that can be used for editing an XML file. I want the script to show a popup and ask for which text to insert.Example:"Insert the server address and press OK."And when the server address has been typed in it should insert that and then go to the next line and show a new popup.These are the three lines I want to edit. Server, to and from.<Actions Context="Author"> <SendEmail> <Server></Server> <To></To> <From></From> <HeaderFields /> </SendEmail> </Actions>Can it be done easily? Link to comment Share on other sites More sharing options...
kylomas Posted February 2, 2013 Share Posted February 2, 2013 scanie, Is there more than one instance of any of these pairs? Is this the entire XML file? Why popup menus? There are many threads dealing with XML files, have you searched the forum for solutions? kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
guinness Posted February 2, 2013 Share Posted February 2, 2013 StringRegExp would be the way to go or the XML UDF that can be found in the examples. Search _GetXML for an idea of syntax, but your will need to amend to suit your needs. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
scanie Posted February 4, 2013 Author Share Posted February 4, 2013 (edited) scanie, Is there more than one instance of any of these pairs? Is this the entire XML file? Why popup menus? There are many threads dealing with XML files, have you searched the forum for solutions? kylomas kylomas, Here is the entire XML file: expandcollapse popup<?xml version="1.0" encoding="UTF-16"?> <Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task"> <RegistrationInfo> <Date>2012-03-01T14:31:50.2136</Date> <Author></Author> </RegistrationInfo> <Triggers> <EventTrigger> <Enabled>true</Enabled> <Subscription><QueryList><Query Id="0" Path="Microsoft-Windows-Backup"><Select Path="Microsoft-Windows-Backup">*[System[Provider[@Name='Microsoft-Windows-Backup'] and EventID=4]]</Select></Query></QueryList></Subscription> </EventTrigger> </Triggers> <Principals> <Principal id="Author"> <UserId></UserId> <LogonType>Password</LogonType> <RunLevel>LeastPrivilege</RunLevel> </Principal> </Principals> <Settings> <IdleSettings> <Duration>PT10M</Duration> <WaitTimeout>PT1H</WaitTimeout> <StopOnIdleEnd>true</StopOnIdleEnd> <RestartOnIdle>false</RestartOnIdle> </IdleSettings> <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy> <DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries> <StopIfGoingOnBatteries>true</StopIfGoingOnBatteries> <AllowHardTerminate>true</AllowHardTerminate> <StartWhenAvailable>false</StartWhenAvailable> <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable> <AllowStartOnDemand>true</AllowStartOnDemand> <Enabled>true</Enabled> <Hidden>false</Hidden> <RunOnlyIfIdle>false</RunOnlyIfIdle> <WakeToRun>false</WakeToRun> <ExecutionTimeLimit>P3D</ExecutionTimeLimit> <Priority>7</Priority> </Settings> <Actions Context="Author"> <SendEmail> <Server></Server> <Subject>Daily Backup Report</Subject> <To></To> <From></From> <Body>SCANERGY-VMM Backup Successful!</Body> <HeaderFields /> </SendEmail> </Actions> </Task> The file is used by Windows Backup and we are using it at work. I want my colleagues to be able to use this at different customers, and all customers have different smtp-addresses and server names. That's why I thought that a popup would be nice. Run the script, fill out the popups and you're good to go! I have searched this forum and also Google for how to do it in Autoit or vbscript.. But I never thought it would be this hard.. It seemed easy when I thought about it Edited February 4, 2013 by scanie Link to comment Share on other sites More sharing options...
jdelaney Posted February 4, 2013 Share Posted February 4, 2013 microsoft.xmldom: $oXML=ObjCreate("Microsoft.XMLDOM") $stest = @DesktopDir & "\xml1.xml" ;$oXML.LoadXML('<td class="questionTitle"><a href="testing an attribute.html" class="asdf" >asdf</a></td>') ; load text of the DOM object $oXML.load($stest) ; load file of xml ;ConsoleWrite ( $oXML.xml & @CRLF) ; change node $result1 = $oXML.selectSingleNode('//SendEmail/To') $result1.text = "whatever you want it to be1" ; change attribute $result2 = $oXML.selectSingleNode('//SendEmail/From') $result2.text = "whatever you want it to be2" ConsoleWrite ( $oXML.xml & @CRLF) exit IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
scanie Posted February 5, 2013 Author Share Posted February 5, 2013 microsoft.xmldom: $oXML=ObjCreate("Microsoft.XMLDOM") $stest = @DesktopDir & "\xml1.xml" ;$oXML.LoadXML('<td class="questionTitle"><a href="testing an attribute.html" class="asdf" >asdf</a></td>') ; load text of the DOM object $oXML.load($stest) ; load file of xml ;ConsoleWrite ( $oXML.xml & @CRLF) ; change node $result1 = $oXML.selectSingleNode('//SendEmail/To') $result1.text = "whatever you want it to be1" ; change attribute $result2 = $oXML.selectSingleNode('//SendEmail/From') $result2.text = "whatever you want it to be2" ConsoleWrite ( $oXML.xml & @CRLF) exit Thank you! It can't get it to prompt me for input though. And it doesn't write anything to my XML file. It doesn't do anything except loading the XML I believe. Did you try it on your side? Do I have to do anything special or install something? Link to comment Share on other sites More sharing options...
HeavenlyDemon Posted February 5, 2013 Share Posted February 5, 2013 (edited) How about this ? expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #region ### START Koda GUI section ### Form= $Form1 = GUICreate("", 140, 119, 192, 124) $Input1 = GUICtrlCreateInput("Server", 8, 8, 121, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER)) $Input2 = GUICtrlCreateInput("To", 8, 32, 121, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER)) $Input3 = GUICtrlCreateInput("From", 8, 56, 121, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER)) $Button1 = GUICtrlCreateButton("Change", 8, 80, 123, 25) GUISetState(@SW_SHOW) #endregion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 $read_server = GUICtrlRead($Input1) $read_to = GUICtrlRead($Input2) $read_from = GUICtrlRead($Input3) $file = @ScriptDir & "\file.xml" ; This is the XML file you posted, edit the path and name to your XML file path and file name $new_file = @ScriptDir & "\NewFile.xml" ; This is the new created file with the edited Server, To and From $file_read = FileRead($file, FileGetSize($file)) $file_read = StringReplace($file_read, " <Server></Server>", " <Server>" & $read_server & "</Server>") $file_read = StringReplace($file_read, " <To></To>", " <To>" & $read_to & "</To>") $file_read = StringReplace($file_read, " <From></From>", " <From>" & $read_from & "</From>") FileDelete($new_file) FileWrite($new_file, $file_read) MsgBox(0, "Msg", "Done") Exit EndSwitch WEnd Edited February 5, 2013 by HeavenlyDemon Link to comment Share on other sites More sharing options...
scanie Posted February 5, 2013 Author Share Posted February 5, 2013 How about this ? expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #region ### START Koda GUI section ### Form= $Form1 = GUICreate("", 140, 119, 192, 124) $Input1 = GUICtrlCreateInput("Server", 8, 8, 121, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER)) $Input2 = GUICtrlCreateInput("To", 8, 32, 121, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER)) $Input3 = GUICtrlCreateInput("From", 8, 56, 121, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER)) $Button1 = GUICtrlCreateButton("Change", 8, 80, 123, 25) GUISetState(@SW_SHOW) #endregion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 $read_server = GUICtrlRead($Input1) $read_to = GUICtrlRead($Input2) $read_from = GUICtrlRead($Input3) $file = @ScriptDir & "\file.xml" ; This is the XML file you posted, edit the path and name to your XML file path and file name $new_file = @ScriptDir & "\NewFile.xml" ; This is the new created file with the edited Server, To and From $file_read = FileRead($file, FileGetSize($file)) $file_read = StringReplace($file_read, " <Server></Server>", " <Server>" & $read_server & "</Server>") $file_read = StringReplace($file_read, " <To></To>", " <To>" & $read_to & "</To>") $file_read = StringReplace($file_read, " <From></From>", " <From>" & $read_from & "</From>") FileDelete($new_file) FileWrite($new_file, $file_read) MsgBox(0, "Msg", "Done") Exit EndSwitch WEnd This was a nice way to do it! It creates the new file but it doesn't have the changes in it. I have tried to find the error but I can't.. Link to comment Share on other sites More sharing options...
jdelaney Posted February 5, 2013 Share Posted February 5, 2013 (edited) works fine for me, but only when i make the XML header valid: <?xml version="1.0" encoding="UTF-8"?> Also, I was just showing how to manipulate the XML, use a gui or msgbox to fill in the rest. To save changes using XML dom, use: $oXML.save('file and path') $oXML=ObjCreate("Microsoft.XMLDOM") $stest = @DesktopDir & "\xml1.xml" ;$oXML.LoadXML('<td class="questionTitle"><a href="testing an attribute.html" class="asdf" >asdf</a></td>') ; load text of the DOM object $oXML.load($stest) ; load file of xml ;ConsoleWrite ( $oXML.xml & @CRLF) ; change node $result1 = $oXML.selectSingleNode('//SendEmail/To') $result1.text = "whatever you want it to be1" ; change attribute $result2 = $oXML.selectSingleNode('//SendEmail/From') $result2.text = "whatever you want it to be2" ConsoleWrite ( $oXML.xml & @CRLF) $oXML.save($stest) Edited February 5, 2013 by jdelaney IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
HeavenlyDemon Posted February 5, 2013 Share Posted February 5, 2013 This was a nice way to do it!It creates the new file but it doesn't have the changes in it. I have tried to find the error but I can't..does it insert the old files data in it or just create a new empty file ? Link to comment Share on other sites More sharing options...
scanie Posted February 6, 2013 Author Share Posted February 6, 2013 does it insert the old files data in it or just create a new empty file ?It creates a new file with the same contents as the original. Link to comment Share on other sites More sharing options...
HeavenlyDemon Posted February 6, 2013 Share Posted February 6, 2013 (edited) check the $file_read = StringReplace($file_read, " <Server></Server>", " <Server>" & $read_server & "</Server>") $file_read = StringReplace($file_read, " <To></To>", " <To>" & $read_to & "</To>") $file_read = StringReplace($file_read, " <From></From>", " <From>" & $read_from & "</From>") what you are saying is that the replace cant find " <Server></Server>" , " <To></To>", " <From></From>" in the xml file copy the exact line from the xml file in the script Edited February 6, 2013 by HeavenlyDemon Link to comment Share on other sites More sharing options...
scanie Posted February 6, 2013 Author Share Posted February 6, 2013 (edited) check the $file_read = StringReplace($file_read, " <Server></Server>", " <Server>" & $read_server & "</Server>") $file_read = StringReplace($file_read, " <To></To>", " <To>" & $read_to & "</To>") $file_read = StringReplace($file_read, " <From></From>", " <From>" & $read_from & "</From>") what you are saying is that the replace cant find " <Server></Server>" , " <To></To>", " <From></From>" in the xml file copy the exact line from the xml file in the script From the script that you provided: $file_read = StringReplace($file_read, " <Server></Server>", " <Server>" & $read_server & "</Server>") $file_read = StringReplace($file_read, " <To></To>", " <To>" & $read_to & "</To>") $file_read = StringReplace($file_read, " <From></From>", " <From>" & $read_from & "</From>") FileDelete($new_file) FileWrite($new_file, $file_read) from my XML: <SendEmail> <Server></Server> <Subject>Daily Backup Report</Subject> <To></To> <From></From> <Body></Body> I got the script from jdelaney to work but I still haven't figured out how to combine it with your GUI Thank you both for your help so far! Edited February 6, 2013 by scanie Link to comment Share on other sites More sharing options...
scanie Posted February 6, 2013 Author Share Posted February 6, 2013 I've finished the script! And it works just the way I wanted! Thank you jdelaney and HeavenlyDemon for your help. I took the best from both of your scripts and combined them to a rainbow Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now