Update/Add XML attribute or elements Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
zotune

Update/Add XML attribute or elements

14 Nov 2014, 09:49

I'm using faqbot's method of finding an xml value (http://www.autohotkey.com/board/topic/8 ... h-a-value/), it works great. Though I'm wondering, can I use a similar method to Update / Add attribute or elements in the actual .xml file (with the built in COM ahk functionality)?

I already asked at Autohotkey.com forums, but I didn't get an answer there. Would greatly appreciate any help :)

Thank you
-Mikael
Coco
Posts: 771
Joined: 29 Sep 2013, 20:37
Contact:

Re: Update/Add XML attribute or elements  Topic is solved

14 Nov 2014, 09:59

Code: Select all

xml_doc =
(
<root>
<child_1 some_attrib="some value">Node Text</child_1>
</root>
)

xml := ComObjCreate("MSXML2.DOMDocument")
xml.setProperty("SelectionLanguage", "XPath") ;// for XP and below
xml.async := false
xml.loadXML(xml_doc)

;// setting / getting attribute(s)
child1 := xml.selectSingleNode("/root/child_1") ;// select the 'child_1' node
child1.setAttribute("some_attrib", "new value") ;// set attribute value
MsgBox % child1.getAttribute("some_attrib") ;// get attribute value

;// creating and appending an element
child_2 := xml.createElement("child_2")
child_2.text := "Some text" ;// set text
xml.documentElement.appendChild(child_2) ;// append to 'root' node

MsgBox % xml.xml ;// show XML representtation of document
return

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: filipemb, mikeyww and 360 guests