Jump to content

XML help


Recommended Posts

Hi,

I need some help updating an XML file using AutoIT. My XML file looks like this:

CODE
<?xml version="1.0"?>

<status script="test1.exe">

</status>

I need to update this each time a new script runs with the name of the new script, i.e. if a script called 'test2.exe' was ran, the script attribute would be updated to 'test2.exe'.

Here is my (NOT WORKING) code, can anybody help me out here ??

; Update status.xml file with current script running
$filename = @ScriptDir & "\status.xml"

$oXML = _CreateMSXMLObj()
If Not IsObj($oXML) Then
    ; log message here
EndIf

$oXML.async = False
$error = $oXML.Load($filename)
If Not $error Then
    ; log message here
EndIf

; XML processing
$oXMLRoot = $oXML.documentElement
$oStatusNode = $oXML.selectSingleNode("//status")
$oStatusNode.setattribute("script", @ScriptName)




Func _CreateMSXMLObj() ; Creates a MSXML instance depending on the version installed on the system
    $xmlObj = ObjCreate("Msxml2.DOMdocument.6.0") ; Latest available, default in Vista
    If IsObj($xmlObj) Then Return $xmlObj
        
    $xmlObj = ObjCreate("Msxml2.DOMdocument.5.0") ; Office 2003
    If IsObj($xmlObj) Then Return $xmlObj
        
    $xmlObj = ObjCreate("Msxml2.DOMdocument.4.0") 
    If IsObj($xmlObj) Then Return $xmlObj
        
    $xmlObj = ObjCreate("Msxml2.DOMdocument.3.0") ; XP and w2k3 server
    If IsObj($xmlObj) Then Return $xmlObj
        
    $xmlObj = ObjCreate("Msxml2.DOMdocument.2.6") ; Win98 ME...
    If IsObj($xmlObj) Then Return $xmlObj
        
    Return 0
    
EndFunc
Link to comment
Share on other sites

Hi,

how should the xml look like after inserting a few scripts? There is also a XMLDOMWrapper in S&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

Link to comment
Share on other sites

Hi,

how should the xml look like after inserting a few scripts? There is also a XMLDOMWrapper in S&S.

Mega

The only thing that changes in the XML is the value of the 'scritp' attribute. Only one script is being run at a tim, so this value should just reflect the running script.

Link to comment
Share on other sites

Hi,

then just read the file and replace the value between <status script=" and >

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

Link to comment
Share on other sites

Your code is fine, you just need to finish it.

If you add this after "setattribute" you will see the xml is correct:

ConsoleWrite($oXML.xml & @CRLF)

You aren't saving it though.

$oXML.save($filename)
Link to comment
Share on other sites

Your code is fine, you just need to finish it.

If you add this after "setattribute" you will see the xml is correct:

ConsoleWrite($oXML.xml & @CRLF)

You aren't saving it though.

$oXML.save($filename)
Thanks man. It works OK now. I guess I'm an idiot for assuming it auto-saved after I wrote to the file.

Thanks again,

jbc1

Link to comment
Share on other sites

Thanks man. It works OK now. I guess I'm an idiot for assuming it auto-saved after I wrote to the file.

Thanks again,

jbc1

You haven't done something dumb enough to be worthy of the "idiot" title. You have achieved the rank of "bonehead".

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...