Jump to content

Updating XML Tags


Recommended Posts

Hi AutoIT'ers!

 

Im fairly new to the language and can see great power in the code. Im trying to Update an XML file using AutoIT, and struggling to get the SRER to function correctly. I've looked through several examples and the ones ive tried, either just add another Line, instead of replacing the current TAG of the same name, or it wipes the full XML and creates a New TAG. 

 

My XML is a very simple flat file: (See below)

<?xml version="1.0" encoding="utf-8"?>
<RemoteLaunchParemeters xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <Username>aa</Username>
  <ServerIP>10.0.0.1</ServerIP>
  <DomainName>LondonDomain</DomainName>
  <ReadOnly>False</ReadOnly>
  <CloudDemoMode>False</CloudDemoMode>
  <DomainName>LondonDomain</DomainName>
</RemoteLaunchParemeters>

 

I want to replace the "aa" in the Username TAG to be blank, so from

  <Username>aa</Username>

to

  <Username></Username>

 

I have tried the below code but have had no joy. Any help would be greatly appreciated. The XML file name is login.params if that helps.


Thanks

Hari

FileXMLreplace.au3

Link to comment
Share on other sites

Local $sFileName = @ScriptDir & "\Filename.xml"
Local $oErrorHandler = ObjEvent("AutoIt.Error", "_XmlErrFunc")
Local $oXMLDoc = ObjCreate("MSXML2.DOMDocument")
    $oXMLDoc.validateOnParse = False
    $oXMLDoc.load($sFileName)
Local $oUserName = $oXMLDoc.selectSingleNode("/RemoteLaunchParemeters/Username")
;~ Read Value of Username Node
ConsoleWrite($oUserName.Text & @CRLF)
;~ Change Value of Username Node
$oUserName.Text = ""
$oXMLDoc.save($sFileName)

Func _XmlErrFunc($oError)
    ConsoleWrite(@ScriptName & " (" & $oError.scriptline & ") : ==> COM Error intercepted !" & @CRLF & _
            @TAB & "err.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _
            @TAB & "err.windescription:" & @TAB & $oError.windescription & @CRLF & _
            @TAB & "err.description is: " & @TAB & $oError.description & @CRLF & _
            @TAB & "err.source is: " & @TAB & @TAB & $oError.source & @CRLF & _
            @TAB & "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _
            @TAB & "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _
            @TAB & "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _
            @TAB & "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _
            @TAB & "err.retcode is: " & @TAB & "0x" & Hex($oError.retcode) & @CRLF & @CRLF)
EndFunc   ;==>_ErrFunc

 

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...