Help parsing data from XML File

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
JustMePatrick
Posts: 3
Joined: 16 Jan 2018, 15:11

Help parsing data from XML File

Post by JustMePatrick » 02 Dec 2022, 06:53

I have searched to try to get an understanding the process to extracting the information I need. I am just not getting it, lol. :headwall:

Here is a example of the format of the xml file that I would be reading:

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
<ArrayOfSessionData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
	<SessionData SessionId="Location/Device/DeviceName 1" SessionName="DeviceName 1" Host="127.0.0.1" Port="23" Proto="Telnet" Session="DeviceName 1" Username="" FileName="" />
</ArrayOfSessionData>
I am wanting to extract the values for SessionId (I will be honing in a specific Location Value as well), alsong with Session Name, Host I'm sure you get the picture.

I've been attempting to RegExMatch but I know I don't understand it enough to know what I should be doing.
Here is my sample code some of which I have based on my research in other similar posts:

Code: Select all

FileRead, XMLData, Sessions.XML; Read XML FileAppend

RegExMatch(XMLData, "s)SessionId(.*?)\/SessionID",SessionID)
AllInfo := ""
AllInfo .= SessionId "`n"
Msgbox, % AllInfo
The results are always blank
Any insight into what I should be doing would be helpful. Thank you in advance. :xmas:

User avatar
mikeyww
Posts: 26601
Joined: 09 Sep 2014, 18:38

Re: Help parsing data from XML File

Post by mikeyww » 02 Dec 2022, 07:54

Just a thought here: there are lots of posts about XML, and I wonder if any of them would help meet your need.

http://www.autohotkey.com/board/topic/89197-xml-build-parse-xml/

viewtopic.php?p=377261#p377261

viewtopic.php?f=76&t=82604

....

JustMePatrick
Posts: 3
Joined: 16 Jan 2018, 15:11

Re: Help parsing data from XML File

Post by JustMePatrick » 05 Dec 2022, 11:23

Thank you Mike! Between your references and googling to find related posts on here. I figured out a solution to what I was trying to achieve.

Code: Select all

txtSessionId := % xml.selectSingleNode("/ArrayOfSessionData/SessionData[" A_Index "]/@SessionId").text 
txtSessionHost := % xml.selectSingleNode("/ArrayOfSessionData/SessionData[" A_Index "]/@Host").text 

Post Reply

Return to “Ask for Help (v1)”