Jump to content
HariKara

Updating XML Keys within a TAG

Recommended Posts

HariKara

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

Share this post


Link to post
Share on other sites
Earthshine

what version of the udf are you using, it's up to 1.1.1.13 now


My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites
HariKara

@Earthshine Im not sure how to check? I've not called any specific UDF in my script and I'm a Newbie at this... How could I check quickly?

 

Thanks

Hari

Share this post


Link to post
Share on other sites
Earthshine
Posted (edited)

where did you get this

#include "_XMLDomWrapper.au3"

 

There is an XML UDF you can use

 

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites
Earthshine

I would use the ones from this site


My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites
HariKara

@Earthshine Thanks... I will download from this site, would this have impact on the code that I have written and resolve the issue im having?


Thanks

Hari

Share this post


Link to post
Share on other sites
Earthshine
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

 

Share this post


Link to post
Share on other sites
HariKara

@EarthshineI have the latest version of AutoIt downloaded on Friday Last week from AutoIT website. and the latest SCIEditor. THe XMLDOMWrapper is the one from the below link

 

 

Share this post


Link to post
Share on other sites
Earthshine
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

 

Share this post


Link to post
Share on other sites
Earthshine

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

 

Share this post


Link to post
Share on other sites
Subz
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

 

Share this post


Link to post
Share on other sites
mLipok
8 hours ago, HariKara said:

THe XMLDOMWrapper is the one from the below link

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

 

  • Like 1

Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library
 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2018-10-11

Share this post


Link to post
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

×