icemax Posted July 1, 2008 Posted July 1, 2008 (edited) Helo fantastic forum I would like to build an tree-menu-application for read-write an xml filethe under example only reads a XML file .... THE QUESTION : How to write AND modify the values and the keys of XML file ?? the Code example for ONLY read:CODE#Include <Constants.au3>#NoTrayIconOpt("TrayOnEventMode", 1)Opt("TrayMenuMode", 1);------| global |--------------------------------------Global $commands = ObjCreate("Scripting.Dictionary");------| XML |---------------------------------- $xml = ObjCreate("Microsoft.XMLDOM") If Not IsObj($xml) Then Exit(1) ; error If Not FileExists("menu.xml") Then Exit(2) ; control ; load $xml.Async = "false" $xml.Load("menu.xml") ; <-------| il file che contiene la struttura; Title $TitoloMenu = $xml.documentElement.getAttribute("TitoloMenu"); traymenu TraySetState(); tooltip TraySetToolTip($TitoloMenu); menu buildMenu($xml); separator TrayCreateItem(""); Exit apps TrayCreateItem("Exit") TrayItemSetOnEvent(-1, "ExitScript")While 1 Sleep(10)WEnd; build recursive menu Func buildMenu( $xml, $query = '/menu/item|/menu/menu', $parent = -1 ) $items = $xml.SelectNodes($query) If ( $items.Length > 0 ) Then For $item In $items If ( $item.nodeName = "menu" ) Then $idSubMenu = TrayCreateMenu($item.GetAttribute("NomeMenu"), $parent) buildMenu($item, 'menu|item', $idSubMenu) ElseIf ( $item.nodeName = "item" ) Then ; recovery a command $caption = $item.GetAttribute("caption") $cmd = $item.GetAttribute("cmd") ; create item $id = TrayCreateItem($caption, $parent) If $cmd <> "" Then $commands.Add($id, $cmd) TrayItemSetOnEvent(-1, "RunCmd") EndIf EndIf Next EndIf EndFunc; run command Func RunCmd() Run($commands.Item(@TRAY_ID)) EndFunc; close Func ExitScript() Exit(0) EndFunc;->>>>>>> I would like to write functionFunc ModifiyXml(); ???????EndFuncFunc WriteNewChild_XML(); ????? thanksendFuncFunc DeleteChild_XML(); ????? thanksendFuncFunc SearchValue_XML(); ????? thanksendFuncattach example of read xml :..example xml file :CODE<?xml version="1.0" encoding="ISO-8859-1"?><menu TitoloMenu="XML-TrayMenu Esempio"> <menu NomeMenu="Utility"> <item caption="Block notes" cmd="notepad.exe" /> <item caption="Explore" cmd="explorer.exe" /> <item caption="Varius" cmd="explorer.exe" /> <menu NomeMenu="Games"> <item caption="Sol Windows XP" cmd="sol.exe" /> </menu> <menu NomeMenu="Games2"> <item caption="WinMine - XP Game" cmd="winmine.exe" /> </menu> </menu> <menu NomeMenu="Varius 2"> <item caption="reboot XP" cmd="example.exe" /> </menu> <item caption="" /> <item caption="Calc" cmd="calc.exe" /> <item caption="Command Prompt" cmd="cmd.exe" /></menu>repeat : THE QUESTION : How to write AND modify the values and the keys/child of XML file ??thanks to everybody for reply Only_Read_Example.rar Edited July 1, 2008 by icemax
Xenobiologist Posted July 1, 2008 Posted July 1, 2008 Hi, there is a XMLWrapper in Scripts & S. Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times
icemax Posted July 1, 2008 Author Posted July 1, 2008 Hi,there is a XMLWrapper in Scripts & S.Megathanks please ... an example for write simil XML structure ??thanks again
weaponx Posted July 1, 2008 Posted July 1, 2008 #include "_XMLDomWrapper.au3" Local $sFile = "test.xml" If FileExists($sFile) Then $ret = _XMLFileOpen($sFile) If $ret = 0 Then Exit ;Define attributes for item node Dim $aKeys[2] = ["caption","cmd"] Dim $aValues[2] ;Create new node under Utility $aValues[0] = "Wordpad" $aValues[1] = "wordpad.exe" _XMLCreateChildNodeWAttr("//menu[@NomeMenu='Utility']","item",$aKeys,$aValues) Else MsgBox(4096, "Error", _XMLError()) EndIf
icemax Posted August 19, 2008 Author Posted August 19, 2008 Hello fantastic forumand ..re-please help : I want to add a node and delete node to schema ??this routine is not works :ADD : routineXMLCreateRootChild("//menu[@NomeMenu='" & $Val_Group & "']","") not works .. do not create node please help for ADD and DELETE nodes or items Thanks Againg to all
weaponx Posted August 19, 2008 Posted August 19, 2008 Your syntax is incorrect. _XMLCreateRootChild ('menu') This will NOT have an attribute. You will need: Dim $aKeys[1] = ["NomeMenu"] Dim $aValues[1] = [$Val_Group] _XMLCreateRootNodeWAttr ('menu',$aKeys,$aValues) I'm not even sure what you are expecting.
icemax Posted August 19, 2008 Author Posted August 19, 2008 Your syntax is incorrect. _XMLCreateRootChild ('menu') This will NOT have an attribute. You will need: Dim $aKeys[1] = ["NomeMenu"] Dim $aValues[1] = [$Val_Group] _XMLCreateRootNodeWAttr ('menu',$aKeys,$aValues) I'm not even sure what you are expecting. TNX for response .. but not works this is my XML structure : <?xml version="1.0" encoding="ISO-8859-1"?> <menu TitoloMenu="XML-treeview example"> <menu NomeMenu="Utility"> <item caption="Block notes" cmd="notepad.exe" /> <item caption="Explore" cmd="explorer.exe" /> <item caption="Varius" cmd="explorer.exe" /> <menu NomeMenu="Games"> <item caption="Sol Windows XP" cmd="sol.exe" /> </menu> <menu NomeMenu="Games2"> <item caption="WinMine - XP Game" cmd="winmine.exe" /> </menu> </menu> <menu NomeMenu="Varius 2"> <item caption="reboot XP" cmd="example.exe" /> </menu> </menu> i want write the new node with name : EXAMPLE or delete the exist node : example <menu NomeMenu="EXAMPLE"> ...bla ..bla </menu> Thanks Again
weaponx Posted August 19, 2008 Posted August 19, 2008 The last piece of code I posted works just fine. I tested it. #include "../_XMLDomWrapper.au3" Local $sFile = "test.xml" If FileExists($sFile) Then $ret = _XMLFileOpen($sFile) If $ret = 0 Then Exit Dim $aKeys[1] = ["NomeMenu"] Dim $aValues[1] = ['EXAMPLE'] _XMLCreateRootNodeWAttr ('menu',$aKeys,$aValues) Else MsgBox(4096, "Error", _XMLError()) EndIf Result: <?xml version="1.0" encoding="ISO-8859-1"?> <menu TitoloMenu="XML-TrayMenu Esempio"> <menu NomeMenu="Utility"> <item caption="Block notes" cmd="notepad.exe"/> <item caption="Explore" cmd="explorer.exe"/> <item caption="Varius" cmd="explorer.exe"/> <menu NomeMenu="Games"> <item caption="Sol Windows XP" cmd="sol.exe"/> </menu> <menu NomeMenu="Games2"> <item caption="WinMine - XP Game" cmd="winmine.exe"/> </menu> <item/> <item caption="Wordpad" cmd="wordpad.exe"/> </menu> <menu NomeMenu="Varius 2"> <item caption="reboot XP" cmd="example.exe"/> </menu> <item caption=""/> <item caption="Calc" cmd="calc.exe"/> <item caption="Command Prompt" cmd="cmd.exe"/> <menu NomeMenu="EXAMPLE"/> </menu>
icemax Posted August 19, 2008 Author Posted August 19, 2008 thanks ... yes yes ...your code alone is perfectbut in my program not works (later I will find the my code problem)please : why your code :1 - not write <menu> at the end : ??2 - ..PLE"/>practically .. your code write :<menu NomeMenu="EXAMPLE"/>but not write :<menu NomeMenu="EXAMPLE"></menu>thanks (very kind)and ..excuse me
weaponx Posted August 19, 2008 Posted August 19, 2008 That is a valid xml tag. You wont see this until there are other nodes inside of it: <menu NomeMenu="EXAMPLE"> <node></node> <node/> </menu> OK: <menu NomeMenu="EXAMPLE"/>
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