XML Class

Editor for AutoHotkey written completely in AutoHotkey.

Moderator: maestrith

User avatar
maestrith
Posts: 726
Joined: 16 Oct 2013, 13:52

XML Class

14 Jun 2017, 13:57

XMLDoc:=new XML("Doc")
XMLDoc.Add("node",{attribute:"value"})
XMLDoc.Add("node",{attribute:"value1"},,1)
Loop,2
{
MsgBox,% XMLDoc[]
MsgBox,% XMLDoc.SSN("//node[@attribute='value1']").xml
XMLDoc.Transform(2)
}

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

AHK Studio OSD GUI Creator
Donations
Discord
All code is done on a Windows 10 PC Running x64 and AutoHotkey x32
User avatar
Joe Glines
Posts: 540
Joined: 30 Sep 2013, 20:49
Facebook: https://www.facebook.com/theAutomatorGuru/
Google: https://plus.google.com/105328929654286634910
GitHub: joetazz
Location: Dallas
Contact:

Re: XML Class

14 Jun 2017, 14:03

This is an amazing Class! While I'm still learning how to use Classes & Xpath, the potential is amazing! :)
Last edited by Joe Glines on 14 Jun 2017, 16:15, edited 2 times in total.
User avatar
Joe Glines
Posts: 540
Joined: 30 Sep 2013, 20:49
Facebook: https://www.facebook.com/theAutomatorGuru/
Google: https://plus.google.com/105328929654286634910
GitHub: joetazz
Location: Dallas
Contact:

Re: XML Class

14 Jun 2017, 16:14

maestrith walked me through using his class a while back. I recorded the video and you can see it


I've uploaded the file and video to my site here which will be part of a series of WebService / API calls.

Thanks again maestrith! This class is a lifesaver! :dance:
User avatar
Joe Glines
Posts: 540
Joined: 30 Sep 2013, 20:49
Facebook: https://www.facebook.com/theAutomatorGuru/
Google: https://plus.google.com/105328929654286634910
GitHub: joetazz
Location: Dallas
Contact:

Re: XML Class

14 Jun 2017, 20:37

In this video maestrith was demonstrating how he can use his class to save / populate user preferences. :lol:
User avatar
hoppfrosch
Posts: 317
Joined: 07 Oct 2013, 04:05
GitHub: hoppfrosch
Location: Rhine-Maine-Area, Hesse, Germany
Contact:

Re: XML Class

26 Jun 2017, 04:09

Where does the function m(....) come from? (Line 63) :think:
User avatar
maestrith
Posts: 726
Joined: 16 Oct 2013, 13:52

Re: XML Class

26 Jun 2017, 05:18

hoppfrosch wrote:Where does the function m(....) come from? (Line 63) :think:

Sorry, I'll add it.
AHK Studio OSD GUI Creator
Donations
Discord
All code is done on a Windows 10 PC Running x64 and AutoHotkey x32
dcdc
Posts: 5
Joined: 07 Feb 2017, 11:19

Re: XML Class

04 Jul 2017, 11:19

Hi,

Great tool, thanks.
Anyway I am very new to AH and a practical example would be providential.
In example, I am trying to simply read one value from the following xml file, specifically the content of unity.ApplicationPath, that is "C:\Users\Public\Documents\Schneider Electric\Unity Pro"

Could you please help? Thank you very much!


Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

User avatar
maestrith
Posts: 726
Joined: 16 Oct 2013, 13:52

Re: XML Class

04 Jul 2017, 11:29

dcdc wrote:Hi,

Great tool, thanks.
Anyway I am very new to AH and a practical example would be providential.
In example, I am trying to simply read one value from the following xml file, specifically the content of unity.ApplicationPath, that is "C:\Users\Public\Documents\Schneider Electric\Unity Pro"

Could you please help? Thank you very much!


Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

AHK Studio OSD GUI Creator
Donations
Discord
All code is done on a Windows 10 PC Running x64 and AutoHotkey x32
User avatar
Joe Glines
Posts: 540
Joined: 30 Sep 2013, 20:49
Facebook: https://www.facebook.com/theAutomatorGuru/
Google: https://plus.google.com/105328929654286634910
GitHub: joetazz
Location: Dallas
Contact:

Re: XML Class

05 Jul 2017, 13:37

I'm on vacation and don't have access to a computer now. .. Will try and get back to it but I'm not back until Jul 18th
dcdc
Posts: 5
Joined: 07 Feb 2017, 11:19

Re: XML Class

07 Jul 2017, 10:29

Yes, great that worked!
One step harder... I am blocked again on an error: in this case the attribute has a "d2p1" namespace, as follows:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



So I use the following code:

Code: [Select all] [Download] GeSHi © Codebox Plus

IfExist, %DTMCatalog% ;Get the STB folder from Unity options xml
{
FileRead, xmlcontents, %DTMCatalog%
NewXML:=New XML("xml")
NewXML.XML.LoadXML(xmlcontents)
DTMInfo_name:=NewXML.SSN("/DTMCatalogueFile/DTMCatalogue/DTMCatalogDataset/DTMInfo[1]/@d2p1:Version").text
}


But I get the error saying "Reference to undeclared namespace prefix: 'd2p1'"
Image

I found the followng information but got a bit stuck anyway:
"If the XPath expression does not include a prefix, it is assumed that the namespace URI is the empty namespace. If your XML includes a default namespace, you must still add a prefix and namespace URI to the XmlNamespaceManager; otherwise, you will not get a node selected"

Thanks
User avatar
maestrith
Posts: 726
Joined: 16 Oct 2013, 13:52

Re: XML Class

07 Jul 2017, 10:50

I updated the script, so get a new copy of that. The only way I have found to use XML with Namespaces is to change the selection language.

Code: [Select all] [Download] GeSHi © Codebox Plus

IfExist, %DTMCatalog% ;Get the STB folder from Unity options xml
{
FileRead, xmlcontents, %DTMCatalog%
NewXML:=New XML("xml")
NewXML.XML.LoadXML(xmlcontents)
NewXML.Language()
DTMInfo_name:=NewXML.SSN("/DTMCatalogueFile/DTMCatalogue/DTMCatalogDataset/DTMInfo[1]/@d2p1:Version").text
}

This "Should" work...I have not tried it with your XML because I do not have it.
AHK Studio OSD GUI Creator
Donations
Discord
All code is done on a Windows 10 PC Running x64 and AutoHotkey x32
dcdc
Posts: 5
Joined: 07 Feb 2017, 11:19

Re: XML Class

10 Jul 2017, 04:30

You're great maestrith, it works well :)
In order to loop through the DTMInfo nodes, and extract some name and version values, I do the following:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



Do you think there is a smoother way? Perhaps using the DTMInfo item inside the while loop.
Attached is the xml file.
DTMCatalog_2.xml
(1.04 MiB) Downloaded 35 times
User avatar
maestrith
Posts: 726
Joined: 16 Oct 2013, 13:52

Re: XML Class

10 Jul 2017, 10:54

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

AHK Studio OSD GUI Creator
Donations
Discord
All code is done on a Windows 10 PC Running x64 and AutoHotkey x32
User avatar
Drugwash
Posts: 560
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania

Re: XML Class

04 Dec 2017, 10:56

I got stuck at the very same issue with prefixed node names while using the default AHK implementation of XML objects (not this class). However the Language trick doesn't work in that case. Anybody has an idea what could be done in that situation?
No offense intended but I'd try to avoid including any extra scripts if possible.
I've deleted my CloudMe account because of GDPR - the now legal base for privacy invasion and data theft.

Return to “AHK Studio”

Who is online

Users browsing this forum: No registered users and 2 guests