Jump to content

Recommended Posts

Posted

Hi All, 

Any AutoIT coders out there able to assist me? I have managed to work out how to update a "TAG", however, I now need to update a Key within the tag. XML code below:

XML CODE:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup">
      <section name="CP.Infrastructure.Properties.Settings" type="System.Configuration.ClientSettingsSection" />
    </sectionGroup>
  </configSections>
  <userSettings>
    <CP.Infrastructure.Properties.Settings>
      <setting name="Dictionary" serializeAs="Xml">
        <value>
<dictionary>
  <items>
    <item key="LoginType">Username</item>
    <item key="LoginUsername">admin</item>
    <item key="LastConnectedServers">127.0.0.1</item>
    <item key="Fingerprint Server: 127.0.0.1">TEXT SPACE EDIT BEND IDEN WREN</item>
    <item key="GettingStarted">False</item>
  </items>
</dictionary></value>
      </setting>
    </CP.Infrastructure.Properties.Settings>
  </userSettings>
</configuration>

 

I want to set the XML key highlighted in RED above from 

    <item key="LoginUsername">admin</item>
 

To

    <item key="LoginUsername"></item>
 

I've tried many scripts but I either get a complete wipeout or nothing changes. Ive attached my base script that I'm trying. 

File2.au3

Posted (edited)

I guess you should make sure you are running the latest AutoIT as well as the Scintilla editor made for it as well

 

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Posted (edited)

ok. good. those XML guru's can probably help you in that case. I'll do some more digging. I would assume you can update a key's value using the UDF, right? so make the value ""

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Posted

found this thread. looks like the example given as an solution could be modified for your purposes, remove the offending node and create a new one maybe?

 

My resources are limited. You must ask the right questions

 

Posted
Local $sFileName = @ScriptDir & "\Filename.xml"
Local $oErrorHandler = ObjEvent("AutoIt.Error", "_XmlErrFunc")
Local $oXMLDoc = ObjCreate("MSXML2.DOMDocument")
    $oXMLDoc.validateOnParse = False
    $oXMLDoc.load($sFileName)
Local $oNode = $oXMLDoc.selectSingleNode('//configuration/userSettings/CP.Infrastructure.Properties.Settings/setting/value/dictionary/items/item[@key="LoginUsername"]')
$oNode.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

 

Posted
  On 4/16/2018 at 1:38 PM, HariKara said:

THe XMLDOMWrapper is the one from the below link

Expand  

But I guess that you download old not recent version XML_1.1.1.13.zip.

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

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
  • Recently Browsing   0 members

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