Leaderboard
Popular Content
Showing content with the highest reputation on 10/04/2022 in Posts
-
Xml2Json UDF - Transform XML to JSON
AspirinJunkie reacted to TheXman for a topic
The tools & UDF's used to parse and process JSON are much more flexible and powerful than the ones for XML. In general, they are also much faster. So I created this Xml2Json UDF to tranform XML to JSON. It consists of 2 functions, _Xml2Json() and _XmlFile2Json(). ;================================================================================================= ; _Xml2Json($sXml, $sXsl = Default) ; ; Author: TheXman (https://www.autoitscript.com/forum/profile/23259-thexman/?tab=field_core_pfield_11) ; ; Description: Transform XML string to JSON ; Parameter(s): $sXml - A string containing a valid XML document. ; $sXsl - [optional] A string containing the XSL stylesheet used for transform. ; Return Value(s): Success - A string containing JSON ; Failure - "" and sets @error to a non-zero value. ; @error 1 = Unable to create XML object ; 2 = Unable to create XSL object ; 3 = Unable to parse XML. Make sure XML is valid. ; 4 = Unable to parse XSL. Make sure XSL is valid. ; 5 = XML Transform failed. Make sure you are using a valid v1.0 stylesheet. ; ; Remarks: MSXML 6.0, the COM component used to do the tranformations, only processes ; XSLT 1.0 stylesheets. If you pass a version 2.0+ stylesheet, you WILL get an ; error. ; ; The XSL stylesheet used by default came from: ; https://www.bjelic.net/2012/08/01/coding/convert-xml-to-json-using-xslt/ ; MIT License - Copyright (c) 2012 Bojan Bjelic ;================================================================================================= ;================================================================================================= ; _XmlFile2Json($sXmlFile, $sXsl = Default) ; ; Author: TheXman (https://www.autoitscript.com/forum/profile/23259-thexman/?tab=field_core_pfield_11) ; ; Description: Transform XML file to JSON ; Parameter(s): $sXmlFile - A string containing a valid XML document file path. ; $sXsl - [optional] A string containing the XSL stylesheet used for transform. ; Return Value(s): Success - A string containing the transformed JSON. ; Failure - "" and sets @error to a non-zero value. ; @error -1 = File does not exist ; 1 = Unable to create XML object ; 2 = Unable to create XSL object ; 3 = Unable to parse XML. Make sure XML is valid. ; 4 = Unable to parse XSL. Make sure XSL is valid. ; 5 = XML Transform failed. Make sure you are using a valid v1.0 stylesheet. ; ; Remarks: MSXML 6.0, the COM component used to do the tranformations, only processes ; XSLT 1.0 stylesheets. If you pass a version 2.0+ stylesheet, you WILL get an ; error. ; ; The XSL stylesheet used by default came from: ; https://www.bjelic.net/2012/08/01/coding/convert-xml-to-json-using-xslt/ ; MIT License - Copyright (c) 2012 Bojan Bjelic ;================================================================================================= The transformation is done by doing an XML Transform using a xml-to-json XSL stylesheet. If you want to use your own xml-to-json XSL stylesheet instead of the default one, then you can supply it in the 2nd parameter. The only caveat is that all values are transformed to strings. That means that numeric XML values will be returned as a strings. For example, the numeric value 10.50 will be returned as "10.50". The UDF comes with a couple of example scripts. One example script, which is below, just shows a sample transformation using the included sample XML file. The second example does the transformation and queries the transformed JSON for information. Example-01 ( uses the included sample XML file, Books.xml ) #AutoIt3Wrapper_AU3Check_Parameters=-w 3 -w 4 -w 5 -w 6 -d #include <Constants.au3> #include "xml2json.au3" #include "jq.au3" ; (https://www.autoitscript.com/forum/files/file/502-jq-udf-a-powerful-flexible-json-processor/) example() Func example() Const $XML_FILE = "books.xml" Local $hTimer = -1 Local $sCmdOutput = "", _ $sJson = "" ;Initialize jq environment _jqInit("C:\Utils\JQ\jq-win64.exe") ;<== Path to jq exe If @error Then Exit MsgBox($MB_ICONERROR + $MB_TOPMOST, "ERROR", "Unable to find jq executable - @error = " & @error) $hTimer = TimerInit() ;Convert XML to JSON $sJson = _XmlFile2Json($XML_FILE) If @error Then Exit MsgBox($MB_ICONERROR + $MB_TOPMOST, "_xmlfile2json() Error", "@error = " & @error) ConsoleWrite(StringFormat("Elapsed time to transform XML to JSON: %.3f seconds", TimerDiff($hTimer) / 1000) & @CRLF) ;Pretty-print JSON $sCmdOutput = _jqPrettyPrintJson($sJson, " ") If @error Then MsgBox($MB_ICONERROR + $MB_TOPMOST, "ERROR", "Pretty-print failed - @error = " & @error & " @extended = " & @extended) ConsoleWrite("ERROR:" & @CRLF & $sCmdOutput & @CRLF) Exit EndIf ConsoleWrite($sCmdOutput & @CRLF) EndFunc Output Elapsed time to transform XML to JSON: 0.003 seconds { "catalog": { "book": [ { "id": "bk101", "author": "Gambardella, Matthew", "title": "XML Developer's Guide", "genre": "Computer", "price": "44.95", "publish_date": "2000-10-01", "description": "An in-depth look at creating applications with XML." }, { "id": "bk102", "author": "Ralls, Kim", "title": "Midnight Rain", "genre": "Fantasy", "price": "5.95", "publish_date": "2000-12-16", "description": "A former architect battles corporate zombies, an evil sorceress, and her own childhood to become queen of the world." }, { "id": "bk103", "author": "Corets, Eva", "title": "Maeve Ascendant", "genre": "Fantasy", "price": "5.95", "publish_date": "2000-11-17", "description": "After the collapse of a nanotechnology society in England, the young survivors lay the foundation for a new society." }, { "id": "bk104", "author": "Corets, Eva", "title": "Oberon's Legacy", "genre": "Fantasy", "price": "5.95", "publish_date": "2001-03-10", "description": "In post-apocalypse England, the mysterious agent known only as Oberon helps to create a new life for the inhabitants of London. Sequel to Maeve Ascendant." }, { "id": "bk105", "author": "Corets, Eva", "title": "The Sundered Grail", "genre": "Fantasy", "price": "5.95", "publish_date": "2001-09-10", "description": "The two daughters of Maeve, half-sisters, battle one another for control of England. Sequel to Oberon's Legacy." }, { "id": "bk106", "author": "Randall, Cynthia", "title": "Lover Birds", "genre": "Romance", "price": "4.95", "publish_date": "2000-09-02", "description": "When Carla meets Paul at an ornithology conference, tempers fly as feathers get ruffled." }, { "id": "bk107", "author": "Thurman, Paula", "title": "Splish Splash", "genre": "Romance", "price": "4.95", "publish_date": "2000-11-02", "description": "A deep sea diver finds true love twenty thousand leagues beneath the sea." }, { "id": "bk108", "author": "Knorr, Stefan", "title": "Creepy Crawlies", "genre": "Horror", "price": "4.95", "publish_date": "2000-12-06", "description": "An anthology of horror stories about roaches, centipedes, scorpions and other insects." }, { "id": "bk109", "author": "Kress, Peter", "title": "Paradox Lost", "genre": "Science Fiction", "price": "6.95", "publish_date": "2000-11-02", "description": "After an inadvertant trip through a Heisenberg Uncertainty Device, James Salway discovers the problems of being quantum." }, { "id": "bk110", "author": "O'Brien, Tim", "title": "Microsoft .NET: The Programming Bible", "genre": "Computer", "price": "36.95", "publish_date": "2000-12-09", "description": "Microsoft's .NET initiative is explored in detail in this deep programmer's reference." }, { "id": "bk111", "author": "O'Brien, Tim", "title": "MSXML3: A Comprehensive Guide", "genre": "Computer", "price": "36.95", "publish_date": "2000-12-01", "description": "The Microsoft MSXML3 parser is covered in detail, with attention to XML DOM interfaces, XSLT processing, SAX and more." }, { "id": "bk112", "author": "Galos, Mike", "title": "Visual Studio 7: A Comprehensive Guide", "genre": "Computer", "price": "49.95", "publish_date": "2001-04-16", "description": "Microsoft Visual Studio 7 is explored in depth, looking at how Visual Basic, Visual C++, C#, and ASP+ are integrated into a comprehensive development environment." } ] } } Xml2Json UDF (2022-12-07).zip1 point -
Autoit and Scite On Win 11
argumentum reacted to AutoitMike for a topic
I got the following error: ! We intercepted a COM Error ! ! err.description is: ! err.windescription: Invalid class string ! err.number is: 800401F3 ! err.lastdllerror is: 0 ! err.scriptline is: 8 ! err.source is: ! err.helpfile is: ! err.helpcontext is: !>15:24:06 AutoIt3.exe ended.rc:123 +>15:24:06 AutoIt3Wrapper Finished. >Exit code: 123 Time: 1.513 It works ok on my win 7 laptop I ordered a full install of Office 2007 on Ebay I'll see how that goes. Thanks1 point -
Will do as it probably makes sense, but I am sure this will not work properly yet at that point in the script as not all of those possible variables have their value known. EDIT: Will add $INP_Icon to Func Convert_required_DirectiveValues() nobody has even tried to use it till now and it wasn't my intent to do the Conversion of %xxx% on all possible directives/INI keywords as their probably will be another can-of-worms I open with that.1 point
-
That is not how it is working. The reason for the multiple options has to do with the portability of SciTE and its tools. When SCITE_USERHOME is defined it is assumed that the AutoIt3Wrapper.ini is located in %SCITE_USERHOME %\AutoIt3Wrapper\AutoIt3Wrapper.ini. This was introduced when settings moved from Program Files to User directories and the "require admin rights to update files in program files" was added to Windows. When SCITE_HOME is defined it is assumed that the AutoIt3Wrapper.ini is located in %SCITE_HOME %\AutoIt3Wrapper\AutoIt3Wrapper.ini. This is the original setting used in SciTE before the previous was added and all configs were in the program directory. Else we assume it is portable and located in the "SciTE.exe directory"\AutoIt3Wrapper\AutoIt3Wrapper.ini. Introduced for the portable option when no Environment variables are defined. There is a long history around this but this is how it has been for a long time now. Close but not correct. see my explanation at the start of this post. Jos1 point
-
Back when the issue regarding not being able to access keys that have periods in them was posted HERE on 9/18, I took a look at the issue and fixed my local copy. Then, I saw the post HERE on 9/28 that had the same issue. After mulling it over a bit, I decided to share my fix (attached below). Even though there are other JSON UDF's available that do not have this issue, I decided that it was still important to offer a fix since this UDF lib is widely used and very fast when doing simple parsing. Of course one can access keys with periods in them by directly accessing the underlying dictionary, where the key/value pairs are actually stored. However, that doesn't address being able to access & manipulate such keys, using dot-notation and bracket-notation, with the Json_Get() and Json_Put() functions. Only 4 lines in the most current version needed to be modified, 2 lines in Json_Get() and 2 lines in Json_Put(). I could go into a detailed analysis of the root cause(s) of the issue and why I chose to fix it the way I did, but I'm sure that most don't care. All anyone really cares about is that it works. 😉 I left the Json_ObjGet() and Json_ObjExists() helper functions as-is. Although those 2 helper functions are related to the issue, they are not needed for Json_Get() and Json_Put() to correctly traverse a mutli-level JSON notation that has special characters like slashes, spaces, brackets, and periods. The example script below shows keys with periods, spaces, brackets, and slashes, being created, accessed, and modified, using Json_Put() and Json_Get(): #include <Constants.au3> ;~ #include "Json.au3" #include "Json(2022-09-18)_TheXman.au3" ;<== Modified json.au3 (only 4 lines updated) Const $JSON = _ '{' & _ ' "dual_engine": {' & _ ' "user_list_data_1": {' & _ ' "https://www.yahoo.com/": {' & _ ' "date_added": "13308840098237395",' & _ ' "engine": 2,' & _ ' "visits_after_expiration": 0' & _ ' }' & _ ' }' & _ ' },' & _ ' "VST.magic": "Test",' & _ ' "VST3.uid": [2229853791, 2455052834, 2533024787],' & _ ' "pluginName": "Omnisphere",' & _ ' "pluginVendor": "Spectrasonics"' & _ '}' json_example() Func json_example() Local $oJson ;Decode JSON into a dictionary object $oJson = Json_Decode($JSON) If @error Then Exit MsgBox($MB_ICONERROR + $MB_TOPMOST, "JSON DECODE ERROR", "@error = " & @error) ;Pretty-print the original JSON log_line("=== Pretty-Printed JSON (original) ===") log_line(Json_Encode($oJson, $JSON_PRETTY_PRINT + $JSON_UNESCAPED_SLASHES, " ") & @CRLF) ;Update an existing key / Add some valid keys with spaces, slashes, and periods Json_Put($oJson, '.dual_engine.user_list_data_1."https://www.yahoo.com/".visits_after_expiration', 3) ;Update key's value to 3 Json_Put($oJson, '."//a.b.c//".". [.] ."', "Value of ridiculous but valid key (. [.] .)") ;Add key Json_Put($oJson, '."//a.b.c//"."/ /"' , "Value of another ridiculous but valid key (/ /)") ;Add key Json_Put($oJson, '."key with spaces"' , "Value of key with spaces") ;Add key Json_Put($oJson, '."lvl1.key"."lvl2.key1"."lvl3.key1"' , "Level 3 Key1") ;Add key using dot-notation Json_Put($oJson, '["lvl1.key"]["lvl2.key1"]["lvl3.key2"]', "Level 3 Key2") ;Add key using bracket-notation ;Pretty-print the updated JSON log_line("=== Pretty-Printed JSON (with keys updated/added) ===") log_line(Json_Encode($oJson, $JSON_PRETTY_PRINT + $JSON_UNESCAPED_SLASHES, " ") & @CRLF) ;Display some of the JSON values log_line('=== Display some JSON keys & values ===') log_line('."//a.b.c//".". [.] ." => ' & Json_Get($oJson, '."//a.b.c//".". [.] ."')) log_line('."//a.b.c//"."/ /" => ' & Json_Get($oJson, '."//a.b.c//"."/ /"')) log_line('."key with spaces" => ' & Json_Get($oJson, '."key with spaces"')) log_line() log_line('.dual_engine.user_list_data_1."https://www.yahoo.com/".date_added => ' & _ Json_Get($oJson, '.dual_engine.user_list_data_1."https://www.yahoo.com/".date_added')) log_line('[dual_engine][user_list_data_1]["https://www.yahoo.com/"][engine] => ' & _ Json_Get($oJson, '[dual_engine][user_list_data_1]["https://www.yahoo.com/"][engine]')) log_line('.dual_engine.user_list_data_1."https://www.yahoo.com/".visits_after_expiration => ' & _ Json_Get($oJson, '.dual_engine.user_list_data_1."https://www.yahoo.com/".visits_after_expiration')) log_line() log_line('."VST.magic" => ' & Json_Get($oJson, '."VST.magic"')) log_line('."VST3.uid"[0] => ' & Json_Get($oJson, '."VST3.uid"[0]')) log_line() log_line('."lvl1.key"."lvl2.key1"."lvl3.key1" => ' & Json_Get($oJson, '."lvl1.key"."lvl2.key1"."lvl3.key1"')) log_line('["lvl1.key"]["lvl2.key1"]["lvl3.key1"] => ' & Json_Get($oJson, '["lvl1.key"]["lvl2.key1"]["lvl3.key1"]')) EndFunc Func log_line($sMsg = "") ConsoleWrite($sMsg & @CRLF) EndFunc Console Output: === Pretty-Printed JSON (original) === { "dual_engine": { "user_list_data_1": { "https://www.yahoo.com/": { "date_added": "13308840098237395", "engine": 2, "visits_after_expiration": 0 } } }, "VST.magic": "Test", "VST3.uid": [ 2229853791, 2455052834, 2533024787 ], "pluginName": "Omnisphere", "pluginVendor": "Spectrasonics" } === Pretty-Printed JSON (with keys updated/added) === { "VST.magic": "Test", "VST3.uid": [ 2229853791, 2455052834, 2533024787 ], "pluginName": "Omnisphere", "pluginVendor": "Spectrasonics", "dual_engine": { "user_list_data_1": { "https://www.yahoo.com/": { "date_added": "13308840098237395", "engine": 2, "visits_after_expiration": 3 } } }, "//a.b.c//": { ". [.] .": "Value of ridiculous but valid key (. [.] .)", "/ /": "Value of another ridiculous but valid key (/ /)" }, "key with spaces": "Value of key with spaces", "lvl1.key": { "lvl2.key1": { "lvl3.key1": "Level 3 Key1", "lvl3.key2": "Level 3 Key2" } } } === Display some JSON keys & values === ."//a.b.c//".". [.] ." => Value of ridiculous but valid key (. [.] .) ."//a.b.c//"."/ /" => Value of another ridiculous but valid key (/ /) ."key with spaces" => Value of key with spaces .dual_engine.user_list_data_1."https://www.yahoo.com/".date_added => 13308840098237395 [dual_engine][user_list_data_1]["https://www.yahoo.com/"][engine] => 2 .dual_engine.user_list_data_1."https://www.yahoo.com/".visits_after_expiration => 3 ."VST.magic" => Test ."VST3.uid"[0] => 2229853791 ."lvl1.key"."lvl2.key1"."lvl3.key1" => Level 3 Key1 ["lvl1.key"]["lvl2.key1"]["lvl3.key1"] => Level 3 Key1 Json(2022-09-18)_TheXman.au31 point
-
well..... miracles won't happen when using AutoIt3 when it doesn't work with basics. This likely is some sort of proxy setup basically disabling most direct (routed) IP traffic and you get these type of errors.1 point
-
I guess all these "issues" you have says something about how often people really use these as this has been like this for years. Made another couple of changes to do the updates for the resources at a different point in the process to ensure all info is know at that point. Try the latest beta which should fix this one. Jos1 point
-
To be honest I never used it. But the eloquence of my explication should have move you so deep, emotionally, that the requested change would have been attended to immediately and with out challenge. You see, that's why I tend to use emojis to compel those I reach 💛 In my prior posting I did not use any emoji, hence the intellectual challenge 💢 In the future, rest assured, a greater number of these will be use 😿1 point
-
In the autoit_changelog.txt you can find : 3.3.14.0 (10th July, 2015) (Release) AutoIt: - Changed: Minimum OS requirements are now Windows XP SP3 and Windows Server 2003 SP2. The newer versions do not list any restrictions regarding Windows XP (as already mentioned by @pixelsearch ).1 point
-
Last Version for Windows XP
RichardL reacted to pixelsearch for a topic
On the same web page we can read this : Overview You can download the main AutoIt package and other related scripting tools from this page. The current version of AutoIt has works on the following operating systems: Windows XP and Windows Server 2003 Windows Vista and Windows Server 2008/2008 R2 Windows 7 / 8 / 10 / 11 So Windows XP is fully supported by the actual version of AutoIt (release 3.3.16.1 dated Sept 19, 2022)1 point -
Help File/Documentation Issues. (Discussion Only)
funkey reacted to pixelsearch for a topic
This function exists in Windows but not in AutoIt. Let's have a look at these 4 msdn web pages : Private fonts : AddFontResourceExW (this function allows a process to use fonts without allowing other processes access to the fonts) RemoveFontResourceExW Public fonts : AddFontResourceW (the fonts can subsequently be used for text output by any application) RemoveFontResourceW Following msdn recommandations, here is a quick script showing how these 4 functions (4, not 2 as in actual AutoIt) could have been scripted. Actually the 2 functions found in AutoIt ( _WinAPI_AddFontResourceEx and _WinAPI_RemoveFontResourceEx ) come directly from Yashied's code (written in 2012) where he mixed the 4 msdn functions to create only 2 AutoIt functions. ; no include files in this script (+++) Global Const $GUI_EVENT_CLOSE = -3, $BS_MULTILINE = 0x2000, $FR_PRIVATE = 0x10, $FR_NOT_ENUM = 0x20 Example() Func Example() Local $sFontFile = StringLeft(@AutoItExe, StringInStr(@AutoItExe, '\', 0, -1) -1) & '\Examples\Helpfile\Extras\SF Square Head Bold.ttf' ; >>>>>>>> Add a private font (not usable by other applications) Local $hGUI = GUICreate("PRIVATE font (not listed in NotePad)", 720, 235) Local $idButton = GUICtrlCreateButton("AutoIt" & @CRLF & "forever", 100, 32, 520, 170, $BS_MULTILINE) _WinAPI_AddFontResourceEx($sFontFile) If @error Then ConsoleWrite("@error 1 = " & @error & @crlf) GUICtrlSetFont($idButton, 28, 0, 0, "SF Square Head Bold") GUISetState() Do Until GUIGetMsg() = $GUI_EVENT_CLOSE ; Clean up resources _WinAPI_RemoveFontResourceEx($sFontFile) If @error Then ConsoleWrite("@error 2 = " & @error & @crlf) GUIDelete($hGUI) ; >>>>>>>> Add a public font (usable by other applications) Local $hGUI = GUICreate("PUBLIC font (listed in NotePad)", 720, 235) Local $idButton = GUICtrlCreateButton("AutoIt" & @CRLF & "forever", 100, 32, 520, 170, $BS_MULTILINE) _WinAPI_AddFontResource($sFontFile) If @error Then ConsoleWrite("@error 3 = " & @error & @crlf) GUICtrlSetFont($idButton, 28, 0, 0, "SF Square Head Bold") GUISetState() Do Until GUIGetMsg() = $GUI_EVENT_CLOSE ; Clean up resources _WinAPI_RemoveFontResource($sFontFile) If @error Then ConsoleWrite("@error 4 = " & @error & @crlf) GUIDelete($hGUI) EndFunc ;==>Example ;---------------------------------------------------------- Func _WinAPI_AddFontResourceEx($sFont, $iFlag = $FR_PRIVATE) ; add private font Local $aRet = DllCall('gdi32.dll', 'int', 'AddFontResourceExW', 'wstr', $sFont, 'dword', $iFlag, 'ptr', 0) If @error Or Not $aRet[0] Then Return SetError(@error, @extended, 0) Return $aRet[0] EndFunc ;==>_WinAPI_AddFontResourceEx ;---------------------------------------------------------- Func _WinAPI_RemoveFontResourceEx($sFont, $iFlag = $FR_PRIVATE) ; remove private font Local $aRet = DllCall('gdi32.dll', 'bool', 'RemoveFontResourceExW', 'wstr', $sFont, 'dword', $iFlag, 'ptr', 0) If @error Or Not $aRet[0] Then Return SetError(@error, @extended, False) Return $aRet[0] EndFunc ;==>_WinAPI_RemoveFontResourceEx ;=========================================================== Func _WinAPI_AddFontResource($sFont) ; add public font Local $aRet = DllCall('gdi32.dll', 'int', 'AddFontResourceW', 'wstr', $sFont) If @error Or Not $aRet[0] Then Return SetError(@error, @extended, 0) Local Const $WM_FONTCHANGE = 0x001D Local Const $HWND_BROADCAST = 0xFFFF DllCall('user32.dll', 'none', 'SendMessage', 'hwnd', $HWND_BROADCAST, 'uint', $WM_FONTCHANGE, 'wparam', 0, 'lparam', 0) Return $aRet[0] EndFunc ;==>_WinAPI_AddFontResource ;=========================================================== Func _WinAPI_RemoveFontResource($sFont) ; remove public font Local $aRet = DllCall('gdi32.dll', 'bool', 'RemoveFontResourceW', 'wstr', $sFont) If @error Or Not $aRet[0] Then Return SetError(@error, @extended, False) Local Const $WM_FONTCHANGE = 0x001D Local Const $HWND_BROADCAST = 0xFFFF DllCall('user32.dll', 'none', 'SendMessage', 'hwnd', $HWND_BROADCAST, 'uint', $WM_FONTCHANGE, 'wparam', 0, 'lparam', 0) Return $aRet[0] EndFunc ;==>_WinAPI_RemoveFontResource1 point