Mecano Posted December 1, 2013 Share Posted December 1, 2013 (edited) Hallo AutoIt lovers, After searching this forum and reading several messages, I composed the following code but is this good? (it works but I want some approval from experts.) _shortcut() Func _shortcut() Local $OutlookSettings = @AppDataDir & "\Microsoft\Outlook\Outlook.xml" If FileExists($OutlookSettings) Then Local $Readonly = StringInStr(FileGetAttrib($OutlookSettings), "R") Local $File = FileOpen($OutlookSettings, 0) If $File <> -1 Then Local $OutlookXML = FileRead($File) FileClose($File) If StringRegExp($OutlookXML, "(?i)<shortcutInit>0</shortcutInit>") Then $OutlookXML = StringReplace($OutlookXML, '<shortcutInit>0</shortcutInit>', _ '<shortcutInit>1</shortcutInit>') If $Readonly Then FileSetAttrib($OutlookSettings, "-R") Local $hFile = FileOpen($OutlookSettings, 130) ; Open file for writing in unicode UTF8 mode FileWrite($hFile, $OutlookXML) FileClose($hFile) If $Readonly Then FileSetAttrib($OutlookSettings, "+R") ; keep readonly EndIf EndIf Else MsgBox(48, "Outlook.xml", "Outlook.xml not found!", 3) Exit EndIf EndFunc ;==>_shortcut part of Outlook.xml : <?xml version="1.0"?> <wundbar> <version>124518</version> <mailInit>1</mailInit> <shortcutInit>1</shortcutInit> <initMail>1</initMail> <initShortcuts>1</initShortcuts> <dataversion>1202</dataversion> <stores> Thanks in advance Edited December 1, 2013 by Mecano Link to comment Share on other sites More sharing options...
karlkar Posted December 1, 2013 Share Posted December 1, 2013 As long as you do not have multiple entities with the same parameter and value then this code is fine. However if you will have to parse more complex XMLs I'd suggest using XML UDF, that you can find here: '?do=embed' frameborder='0' data-embedContent>> Link to comment Share on other sites More sharing options...
Mecano Posted December 1, 2013 Author Share Posted December 1, 2013 Thanks for the answer and pointing to XML UDF, My concern was about StringRegExp ( pattern pcrepattern ) and FileOpen($OutlookSettings, 130) ; Open file for writing in unicode UTF8 mode Link to comment Share on other sites More sharing options...
Mecano Posted April 13, 2015 Author Share Posted April 13, 2015 One other question, if I want to remove the line <shortcutInit>0</shortcutInit> or <shortcutInit>1</shortcutInit> whats the correct pattern? This will leave a empty line If StringRegExp($OutlookXML, "(?i)<shortcutInit>0</shortcutInit>") Then $OutlookXML = StringReplace($OutlookXML, '<shortcutInit>0</shortcutInit>', '') Link to comment Share on other sites More sharing options...
mikell Posted April 13, 2015 Share Posted April 13, 2015 (edited) $OutlookXML = StringRegExpReplace($OutlookXML, '.*<shortcutInit>\d</shortcutInit>.*\R', "") You have to remove also the leading/trailing space(s) and the newline sequence Edited April 13, 2015 by mikell Link to comment Share on other sites More sharing options...
jdelaney Posted April 14, 2015 Share Posted April 14, 2015 (edited) XML dom will be soooo much easier. You can always brute force a regexp to work, but why do that when there are com objects specifically for your question? Example Edited April 14, 2015 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...
Mecano Posted April 14, 2015 Author Share Posted April 14, 2015 (edited) @jdelaney thanx, but see mine openings question. @mikell excellent solution, works perfect never thought of StringRegExpReplace For non-digits can i use this, example: <textversion>False</textversion> $OutlookXML = StringRegExpReplace($OutlookXML, '.*<textversion>(.*)</textversion>.*\R', "") Edited April 14, 2015 by Mecano Link to comment Share on other sites More sharing options...
jdelaney Posted April 14, 2015 Share Posted April 14, 2015 (edited) Hallo AutoIt lovers, After searching this forum and reading several messages, I composed the following code but is this good? I would suggest this is not a 'good' route, and you should use a tool that's more suited for it. I would also suggest, that this is a much better route: Local $oXML = ObjCreate("Microsoft.XMLDOM") $oXML.load("test.xml") $oShortcutInit = $oXML.SelectSingleNode("//shortcutInit") $oShortcutInit.text = Int($oShortcutInit.text) + 1 $oXML.save("test.xml") Edited April 14, 2015 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...
Mecano Posted April 17, 2015 Author Share Posted April 17, 2015 @jdelaney, gonna give it a try, time to learn AutoIt/Microsoft.XMLDOM Thanks for reply 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