XML Class

Editor for AutoHotkey written completely in AutoHotkey.

Moderator: maestrith

User avatar
maestrith
Posts: 738
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

Class XML{
	keep:=[]
	__Get(x=""){
		return this.XML.xml
	}__New(param*){
		;temp.preserveWhiteSpace:=1
		root:=param.1,file:=param.2,file:=file?file:root ".xml",temp:=ComObjCreate("MSXML2.DOMDocument"),temp.SetProperty("SelectionLanguage","XPath"),this.xml:=temp,this.file:=file,XML.keep[root]:=this
		if(FileExist(file)){
			FileRead,info,%file%
			if(info=""){
				this.xml:=this.CreateElement(temp,root)
				FileDelete,%file%
			}else
				temp.LoadXML(info),this.xml:=temp
		}else
			this.xml:=this.CreateElement(temp,root)
	}Add(XPath,att:="",text:="",dup:=0){
		p:="/",add:=(next:=this.SSN("//" XPath))?1:0,last:=SubStr(XPath,InStr(XPath,"/",0,0)+1)
		if(!next.xml){
			next:=this.SSN("//*")
			for a,b in StrSplit(XPath,"/")
				p.="/" b,next:=(x:=this.SSN(p))?x:next.AppendChild(this.XML.CreateElement(b))
		}if(dup&&add)
			next:=next.ParentNode.AppendChild(this.XML.CreateElement(last))
		for a,b in att
			next.SetAttribute(a,b)
		if(text!="")
			next.text:=text
		return next
	}CreateElement(doc,root){
		return doc.AppendChild(this.XML.CreateElement(root)).ParentNode
	}EA(XPath,att:=""){
		list:=[]
		if(att)
			return XPath.NodeName?SSN(XPath,"@" att).text:this.SSN(XPath "/@" att).text
		nodes:=XPath.NodeName?XPath.SelectNodes("@*"):nodes:=this.SN(XPath "/@*")
		while(nn:=nodes.item[A_Index-1])
			list[nn.NodeName]:=nn.text
		return list
	}Find(info*){
		static last:=[]
		doc:=info.1.NodeName?info.1:this.xml
		if(info.1.NodeName)
			node:=info.2,find:=info.3,return:=info.4!=""?"SelectNodes":"SelectSingleNode",search:=info.4
		else
			node:=info.1,find:=info.2,return:=info.3!=""?"SelectNodes":"SelectSingleNode",search:=info.3
		if(InStr(info.2,"descendant"))
			last.1:=info.1,last.2:=info.2,last.3:=info.3,last.4:=info.4
		if(InStr(find,"'"))
			return doc[return](node "[.=concat('" RegExReplace(find,"'","'," Chr(34) "'" Chr(34) ",'") "')]/.." (search?"/" search:""))
		else
			return doc[return](node "[.='" find "']/.." (search?"/" search:""))
	}Get(XPath,Default){
		text:=this.SSN(XPath).text
		return text?text:Default
	}Language(Language:="XSLPattern"){
		this.XML.SetProperty("SelectionLanguage",Language)
	}ReCreate(XPath,new){
		rem:=this.SSN(XPath),rem.ParentNode.RemoveChild(rem),new:=this.Add(new)
		return new
	}Save(x*){
		if(x.1=1)
			this.Transform()
		if(this.XML.SelectSingleNode("*").xml="")
			return m("Errors happened while trying to save " this.file ". Reverting to old version of the XML")
		filename:=this.file?this.file:x.1.1,ff:=FileOpen(filename,0),text:=ff.Read(ff.length),ff.Close()
		if(!this[])
			return m("Error saving the " this.file " XML.  Please get in touch with maestrith if this happens often")
		if(text!=this[])
			file:=FileOpen(filename,"rw"),file.Seek(0),file.Write(this[]),file.Length(file.Position)
	}SSN(XPath){
		return this.XML.SelectSingleNode(XPath)
	}SN(XPath){
		return this.XML.SelectNodes(XPath)
	}Transform(){
		static
		if(!IsObject(xsl))
			xsl:=ComObjCreate("MSXML2.DOMDocument"),xsl.loadXML("<xsl:stylesheet version=""1.0"" xmlns:xsl=""http://www.w3.org/1999/XSL/Transform""><xsl:output method=""xml"" indent=""yes"" encoding=""UTF-8""/><xsl:template match=""@*|node()""><xsl:copy>`n<xsl:apply-templates select=""@*|node()""/><xsl:for-each select=""@*""><xsl:text></xsl:text></xsl:for-each></xsl:copy>`n</xsl:template>`n</xsl:stylesheet>"),style:=null
		this.XML.TransformNodeToObject(xsl,this.xml)
	}Under(under,node,att:="",text:="",list:=""){
		new:=under.AppendChild(this.XML.CreateElement(node)),new.text:=text
		for a,b in att
			new.SetAttribute(a,b)
		for a,b in StrSplit(list,",")
			new.SetAttribute(b,att[b])
		return new
	}
}SSN(node,XPath){
	return node.SelectSingleNode(XPath)
}SN(node,XPath){
	return node.SelectNodes(XPath)
}m(x*){
	active:=WinActive("A")
	ControlGetFocus,Focus,A
	ControlGet,hwnd,hwnd,,%Focus%,ahk_id%active%
	static list:={btn:{oc:1,ari:2,ync:3,yn:4,rc:5,ctc:6},ico:{"x":16,"?":32,"!":48,"i":64}},msg:=[],msgbox
	list.title:="XML Class",list.def:=0,list.time:=0,value:=0,msgbox:=1,txt:=""
	for a,b in x
		obj:=StrSplit(b,":"),(vv:=List[obj.1,obj.2])?(value+=vv):(list[obj.1]!="")?(List[obj.1]:=obj.2):txt.=b "`n"
	msg:={option:value+262144+(list.def?(list.def-1)*256:0),title:list.title,time:list.time,txt:txt}
	Sleep,120
	MsgBox,% msg.option,% msg.title,% msg.txt,% msg.time
	msgbox:=0
	for a,b in {OK:value?"OK":"",Yes:"YES",No:"NO",Cancel:"CANCEL",Retry:"RETRY"}
		IfMsgBox,%a%
		{
			WinActivate,ahk_id%active%
			ControlFocus,%Focus%,ahk_id%active%
			return b
		}
}
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: 562
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: 562
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: 562
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: 328
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: 738
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

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<options version="410">
	<!--group unity.Options-->
	<!--group unity.General-->
	<entryvalue ident="unity.AutoIncrementProjectVer" value="1"></entryvalue>
	<entryvalue ident="unity.AutoCompletion" value="1"></entryvalue>
	<entryvalue ident="unity.DisplayErrorMode" value="0"></entryvalue>
	<entryvalue ident="unity.OpeninContextActive" value="1"></entryvalue>
	<entryvalue ident="unity.DisplayModifiedSections" value="1"></entryvalue>
	<!--group unity.Paths-->
	<entryvalue ident="unity.ApplicationPath" value="C:\Users\Public\Documents\Schneider Electric\Unity Pro"></entryvalue>
	<entryvalue ident="unity.SourcePath" value="C:\Users\Public\Documents\Schneider Electric\Unity Pro"></entryvalue>
	<entryvalue ident="unity.XVMPath" value="C:\Users\Public\Documents\Schneider Electric\Unity Pro"></entryvalue>
	<entryvalue ident="unity.TemplatePath" value="C:\Users\Public\Documents\Schneider Electric\Unity Pro"></entryvalue>
	<entryvalue ident="unity.TemplateFile" value=""></entryvalue>
	<entryvalue ident="unity.CustomLibraryPath" value="C:\ProgramData\Schneider Electric\Unity Pro\CustomLibset\V11.0"></entryvalue>
	<entryvalue ident="unity.WorkingPath" value="C:\"></entryvalue>
	<entryvalue ident="unity.LogPath" value="C:\ProgramData\Schneider Electric\Unity Pro\"></entryvalue>
	<!--group unity.DataLanguages-->
	<!--group unity.SpreadsheetBehavior-->
	<entryvalue ident="unity.CtrlTreeMoveStyle" value="4"></entryvalue>
	<entryvalue ident="unity.CtrlTreeOpenSessionMode" value="1"></entryvalue>
	<!--group unity.Languages-->
	<entryvalue ident="unity.AutoSetVarOnGraphObj" value="0"></entryvalue>
	<entryvalue ident="unity.RefineBehaviour" value="0"></entryvalue>
	<!--group unity.LL984-->
	<entryvalue ident="unity.ShowLatchedCoils" value="0"></entryvalue>
	<entryvalue ident="unity.Reuse984EditorNetwork" value="1"></entryvalue>
	<!--group unity.Mnemonics-->
	<entryvalue ident="unity.-][-" value="NO"></entryvalue>
	<entryvalue ident="unity.-]\[-" value="NC"></entryvalue>
	<entryvalue ident="unity.-]P[-" value="PTC"></entryvalue>
	<entryvalue ident="unity.-]N[-" value="NTC"></entryvalue>
	<entryvalue ident="unity.|SHRT" value="VTS"></entryvalue>
	<entryvalue ident="unity.-SHRT" value="HSH"></entryvalue>
	<entryvalue ident="unity.-( )-" value="CNR"></entryvalue>
	<entryvalue ident="unity.-(L)-" value="CR"></entryvalue>
	<entryvalue ident="unity.L9_SKP" value="SKP"></entryvalue>
	<entryvalue ident="unity.L9_UCTR" value="UCT"></entryvalue>
	<entryvalue ident="unity.L9_DCTR" value="DCT"></entryvalue>
	<entryvalue ident="unity.L9_T1" value="T1"></entryvalue>
	<entryvalue ident="unity.L9_T01" value="T0"></entryvalue>
	<entryvalue ident="unity.L9_T001" value="T00"></entryvalue>
	<entryvalue ident="unity.L9_ADD" value="ADD"></entryvalue>
	<entryvalue ident="unity.L9_SUB" value="SUB"></entryvalue>
	<entryvalue ident="unity.L9_MUL" value="MUL"></entryvalue>
	<entryvalue ident="unity.L9_DIV" value="DIV"></entryvalue>
	<entryvalue ident="unity.L9_R2T" value="RT"></entryvalue>
	<entryvalue ident="unity.L9_T2R" value="TR"></entryvalue>
	<entryvalue ident="unity.L9_T2T" value="TT"></entryvalue>
	<entryvalue ident="unity.L9_BLKM" value="BLK"></entryvalue>
	<entryvalue ident="unity.L9_FIN" value="FIN"></entryvalue>
	<entryvalue ident="unity.L9_FOUT" value="FOU"></entryvalue>
	<entryvalue ident="unity.L9_SRCH" value="SRC"></entryvalue>
	<entryvalue ident="unity.L9_STAT" value="STA"></entryvalue>
	<entryvalue ident="unity.L9_AND" value="AND"></entryvalue>
	<entryvalue ident="unity.L9_OR" value="OR"></entryvalue>
	<entryvalue ident="unity.L9_CMPR" value="CMP"></entryvalue>
	<entryvalue ident="unity.L9_SENS" value="SEN"></entryvalue>
	<entryvalue ident="unity.L9_MBIT" value="MBI"></entryvalue>
	<entryvalue ident="unity.L9_COMP" value="COM"></entryvalue>
	<entryvalue ident="unity.L9_XOR" value="XOR"></entryvalue>
	<entryvalue ident="unity.L9_BROT" value="BRO"></entryvalue>
	<!--group unity.Connection-->
	<entryvalue ident="unity.ConnectionIdentification" value="WIN-GU2DRMCAR4H"></entryvalue>
	<entryvalue ident="unity.ConnectionMode" value="1"></entryvalue>
	<!--group unity.OperatorScreens-->
	<!--group unity.OSGrid-->
	<entryvalue ident="unity.Grid" value="0"></entryvalue>
	<entryvalue ident="unity.Step" value="20"></entryvalue>
	<entryvalue ident="unity.SnapToGrid" value="0"></entryvalue>
	<!--group unity.OSEdit-->
	<entryvalue ident="unity.MousePos" value="1"></entryvalue>
	<entryvalue ident="unity.VScrollBar" value="1"></entryvalue>
	<entryvalue ident="unity.HScrollBar" value="1"></entryvalue>
	<!--group unity.OSOnLineMode-->
	<entryvalue ident="unity.EditConnect" value="1"></entryvalue>
	<entryvalue ident="unity.EnableSel" value="1"></entryvalue>
	<!--group unity.OSDefaultScreenSize-->
	<entryvalue ident="unity.cxScreen" value="1280"></entryvalue>
	<entryvalue ident="unity.cyScreen" value="1024"></entryvalue>
	<!--group unity.OSScreenOpening-->
	<entryvalue ident="unity.MultiInstance" value="1"></entryvalue>
	<!--group converters.ConversionOptions-->
	<entryvalue ident="converters.SplitSections" value="1"></entryvalue>
	<entryvalue ident="converters.NetworksToSections" value="30"></entryvalue>
	<entryvalue ident="converters.SepIgnoreJumps" value="0"></entryvalue>
	<entryvalue ident="converters.SymToTopo" value="0"></entryvalue>
	<entryvalue ident="converters.FlatAddressesOnly" value="0"></entryvalue>
	<!--group converters.PL7-->
	<entryvalue ident="converters.TRANSITION_OPTIMIZATION" value="0"></entryvalue>
	<entryvalue ident="converters.STEP_STATE_EXPLICIT_DEFINITION" value="0"></entryvalue>
	<entryvalue ident="converters.SYMBOL_AS_STEP_NAME" value="0"></entryvalue>
	<!--group converters.Concept-->
	<entryvalue ident="converters.VarsAtEmptyPins" value="0"></entryvalue>
	<entryvalue ident="converters.DisAssignementCheck" value="1"></entryvalue>
	<entryvalue ident="converters.GenericEF" value="0"></entryvalue>
	<entryvalue ident="converters.LDNetworkDistance" value="0"></entryvalue>
	<entryvalue ident="converters.TxSubstProc" value="0"></entryvalue>
	<entryvalue ident="converters.SubsQDMF" value="0"></entryvalue>
	<entryvalue ident="converters.CriticalLDGraphDepth" value="43"></entryvalue>
</options>
User avatar
maestrith
Posts: 738
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

#SingleInstance,Force
attribute:="unity.ApplicationPath"
xmlcontents=
(
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<options version="410">
	<!--group unity.Options-->
	<!--group unity.General-->
	<entryvalue ident="unity.AutoIncrementProjectVer" value="1"></entryvalue>
	<entryvalue ident="unity.AutoCompletion" value="1"></entryvalue>
	<entryvalue ident="unity.DisplayErrorMode" value="0"></entryvalue>
	<entryvalue ident="unity.OpeninContextActive" value="1"></entryvalue>
	<entryvalue ident="unity.DisplayModifiedSections" value="1"></entryvalue>
	<!--group unity.Paths-->
	<entryvalue ident="unity.ApplicationPath" value="C:\Users\Public\Documents\Schneider Electric\Unity Pro"></entryvalue>
	<entryvalue ident="unity.SourcePath" value="C:\Users\Public\Documents\Schneider Electric\Unity Pro"></entryvalue>
	<entryvalue ident="unity.XVMPath" value="C:\Users\Public\Documents\Schneider Electric\Unity Pro"></entryvalue>
	<entryvalue ident="unity.TemplatePath" value="C:\Users\Public\Documents\Schneider Electric\Unity Pro"></entryvalue>
	<entryvalue ident="unity.TemplateFile" value=""></entryvalue>
	<entryvalue ident="unity.CustomLibraryPath" value="C:\ProgramData\Schneider Electric\Unity Pro\CustomLibset\V11.0"></entryvalue>
	<entryvalue ident="unity.WorkingPath" value="C:\"></entryvalue>
	<entryvalue ident="unity.LogPath" value="C:\ProgramData\Schneider Electric\Unity Pro\"></entryvalue>
	<!--group unity.DataLanguages-->
	<!--group unity.SpreadsheetBehavior-->
	<entryvalue ident="unity.CtrlTreeMoveStyle" value="4"></entryvalue>
	<entryvalue ident="unity.CtrlTreeOpenSessionMode" value="1"></entryvalue>
	<!--group unity.Languages-->
	<entryvalue ident="unity.AutoSetVarOnGraphObj" value="0"></entryvalue>
	<entryvalue ident="unity.RefineBehaviour" value="0"></entryvalue>
	<!--group unity.LL984-->
	<entryvalue ident="unity.ShowLatchedCoils" value="0"></entryvalue>
	<entryvalue ident="unity.Reuse984EditorNetwork" value="1"></entryvalue>
	<!--group unity.Mnemonics-->
	<entryvalue ident="unity.-][-" value="NO"></entryvalue>
	<entryvalue ident="unity.-]\[-" value="NC"></entryvalue>
	<entryvalue ident="unity.-]P[-" value="PTC"></entryvalue>
	<entryvalue ident="unity.-]N[-" value="NTC"></entryvalue>
	<entryvalue ident="unity.|SHRT" value="VTS"></entryvalue>
	<entryvalue ident="unity.-SHRT" value="HSH"></entryvalue>
	<entryvalue ident="unity.-( )-" value="CNR"></entryvalue>
	<entryvalue ident="unity.-(L)-" value="CR"></entryvalue>
	<entryvalue ident="unity.L9_SKP" value="SKP"></entryvalue>
	<entryvalue ident="unity.L9_UCTR" value="UCT"></entryvalue>
	<entryvalue ident="unity.L9_DCTR" value="DCT"></entryvalue>
	<entryvalue ident="unity.L9_T1" value="T1"></entryvalue>
	<entryvalue ident="unity.L9_T01" value="T0"></entryvalue>
	<entryvalue ident="unity.L9_T001" value="T00"></entryvalue>
	<entryvalue ident="unity.L9_ADD" value="ADD"></entryvalue>
	<entryvalue ident="unity.L9_SUB" value="SUB"></entryvalue>
	<entryvalue ident="unity.L9_MUL" value="MUL"></entryvalue>
	<entryvalue ident="unity.L9_DIV" value="DIV"></entryvalue>
	<entryvalue ident="unity.L9_R2T" value="RT"></entryvalue>
	<entryvalue ident="unity.L9_T2R" value="TR"></entryvalue>
	<entryvalue ident="unity.L9_T2T" value="TT"></entryvalue>
	<entryvalue ident="unity.L9_BLKM" value="BLK"></entryvalue>
	<entryvalue ident="unity.L9_FIN" value="FIN"></entryvalue>
	<entryvalue ident="unity.L9_FOUT" value="FOU"></entryvalue>
	<entryvalue ident="unity.L9_SRCH" value="SRC"></entryvalue>
	<entryvalue ident="unity.L9_STAT" value="STA"></entryvalue>
	<entryvalue ident="unity.L9_AND" value="AND"></entryvalue>
	<entryvalue ident="unity.L9_OR" value="OR"></entryvalue>
	<entryvalue ident="unity.L9_CMPR" value="CMP"></entryvalue>
	<entryvalue ident="unity.L9_SENS" value="SEN"></entryvalue>
	<entryvalue ident="unity.L9_MBIT" value="MBI"></entryvalue>
	<entryvalue ident="unity.L9_COMP" value="COM"></entryvalue>
	<entryvalue ident="unity.L9_XOR" value="XOR"></entryvalue>
	<entryvalue ident="unity.L9_BROT" value="BRO"></entryvalue>
	<!--group unity.Connection-->
	<entryvalue ident="unity.ConnectionIdentification" value="WIN-GU2DRMCAR4H"></entryvalue>
	<entryvalue ident="unity.ConnectionMode" value="1"></entryvalue>
	<!--group unity.OperatorScreens-->
	<!--group unity.OSGrid-->
	<entryvalue ident="unity.Grid" value="0"></entryvalue>
	<entryvalue ident="unity.Step" value="20"></entryvalue>
	<entryvalue ident="unity.SnapToGrid" value="0"></entryvalue>
	<!--group unity.OSEdit-->
	<entryvalue ident="unity.MousePos" value="1"></entryvalue>
	<entryvalue ident="unity.VScrollBar" value="1"></entryvalue>
	<entryvalue ident="unity.HScrollBar" value="1"></entryvalue>
	<!--group unity.OSOnLineMode-->
	<entryvalue ident="unity.EditConnect" value="1"></entryvalue>
	<entryvalue ident="unity.EnableSel" value="1"></entryvalue>
	<!--group unity.OSDefaultScreenSize-->
	<entryvalue ident="unity.cxScreen" value="1280"></entryvalue>
	<entryvalue ident="unity.cyScreen" value="1024"></entryvalue>
	<!--group unity.OSScreenOpening-->
	<entryvalue ident="unity.MultiInstance" value="1"></entryvalue>
	<!--group converters.ConversionOptions-->
	<entryvalue ident="converters.SplitSections" value="1"></entryvalue>
	<entryvalue ident="converters.NetworksToSections" value="30"></entryvalue>
	<entryvalue ident="converters.SepIgnoreJumps" value="0"></entryvalue>
	<entryvalue ident="converters.SymToTopo" value="0"></entryvalue>
	<entryvalue ident="converters.FlatAddressesOnly" value="0"></entryvalue>
	<!--group converters.PL7-->
	<entryvalue ident="converters.TRANSITION_OPTIMIZATION" value="0"></entryvalue>
	<entryvalue ident="converters.STEP_STATE_EXPLICIT_DEFINITION" value="0"></entryvalue>
	<entryvalue ident="converters.SYMBOL_AS_STEP_NAME" value="0"></entryvalue>
	<!--group converters.Concept-->
	<entryvalue ident="converters.VarsAtEmptyPins" value="0"></entryvalue>
	<entryvalue ident="converters.DisAssignementCheck" value="1"></entryvalue>
	<entryvalue ident="converters.GenericEF" value="0"></entryvalue>
	<entryvalue ident="converters.LDNetworkDistance" value="0"></entryvalue>
	<entryvalue ident="converters.TxSubstProc" value="0"></entryvalue>
	<entryvalue ident="converters.SubsQDMF" value="0"></entryvalue>
	<entryvalue ident="converters.CriticalLDGraphDepth" value="43"></entryvalue>
</options>
)
NewXML:=New XML("xml")
NewXML.XML.LoadXML(xmlcontents)
UnityPath:=NewXML.SSN("//*[@ident='" attribute "']/@value").text
MsgBox,%UnityPath%

Class XML{
	keep:=[]
	__Get(x=""){
		return this.XML.xml
	}__New(param*){
		;temp.preserveWhiteSpace:=1
		root:=param.1,file:=param.2,file:=file?file:root ".xml",temp:=ComObjCreate("MSXML2.DOMDocument")
		this.xml:=temp,this.file:=file,XML.keep[root]:=this
		temp.SetProperty("SelectionLanguage","XPath")
		if(FileExist(file)){
			FileRead,info,%file%
			if(info=""){
				this.xml:=this.CreateElement(temp,root)
				FileDelete,%file%
			}else
				temp.LoadXML(info),this.xml:=temp
		}else
			this.xml:=this.CreateElement(temp,root)
	}Add(XPath,att:="",text:="",dup:=0){
		p:="/",add:=(next:=this.SSN("//" XPath))?1:0,last:=SubStr(XPath,InStr(XPath,"/",0,0)+1)
		if(!next.xml){
			next:=this.SSN("//*")
			for a,b in StrSplit(XPath,"/")
				p.="/" b,next:=(x:=this.SSN(p))?x:next.AppendChild(this.XML.CreateElement(b))
		}if(dup&&add)
			next:=next.ParentNode.AppendChild(this.XML.CreateElement(last))
		for a,b in att
			next.SetAttribute(a,b)
		if(text!="")
			next.text:=text
		return next
	}CreateElement(doc,root){
		return doc.AppendChild(this.XML.CreateElement(root)).ParentNode
	}EA(XPath,att:=""){
		list:=[]
		if(att)
			return XPath.NodeName?SSN(XPath,"@" att).text:this.SSN(XPath "/@" att).text
		nodes:=XPath.NodeName?XPath.SelectNodes("@*"):nodes:=this.SN(XPath "/@*")
		while(nn:=nodes.item[A_Index-1])
			list[nn.NodeName]:=nn.text
		return list
	}Find(info*){
		static last:=[]
		doc:=info.1.NodeName?info.1:this.xml
		if(info.1.NodeName)
			node:=info.2,find:=info.3,return:=info.4!=""?"SelectNodes":"SelectSingleNode",search:=info.4
		else
			node:=info.1,find:=info.2,return:=info.3!=""?"SelectNodes":"SelectSingleNode",search:=info.3
		if(InStr(info.2,"descendant"))
			last.1:=info.1,last.2:=info.2,last.3:=info.3,last.4:=info.4
		if(InStr(find,"'"))
			return doc[return](node "[.=concat('" RegExReplace(find,"'","'," Chr(34) "'" Chr(34) ",'") "')]/.." (search?"/" search:""))
		else
			return doc[return](node "[.='" find "']/.." (search?"/" search:""))
	}Get(XPath,Default){
		text:=this.SSN(XPath).text
		return text?text:Default
	}ReCreate(XPath,new){
		rem:=this.SSN(XPath),rem.ParentNode.RemoveChild(rem),new:=this.Add(new)
		return new
	}Save(x*){
		if(x.1=1)
			this.Transform()
		if(this.XML.SelectSingleNode("*").xml="")
			return m("Errors happened while trying to save " this.file ". Reverting to old version of the XML")
		filename:=this.file?this.file:x.1.1,ff:=FileOpen(filename,0),text:=ff.Read(ff.length),ff.Close()
		if(!this[])
			return m("Error saving the " this.file " XML.  Please get in touch with maestrith if this happens often")
		if(text!=this[])
			file:=FileOpen(filename,"rw"),file.Seek(0),file.Write(this[]),file.Length(file.Position)
	}SSN(XPath){
		return this.XML.SelectSingleNode(XPath)
	}SN(XPath){
		return this.XML.SelectNodes(XPath)
	}Transform(){
		static
		if(!IsObject(xsl))
			xsl:=ComObjCreate("MSXML2.DOMDocument"),xsl.loadXML("<xsl:stylesheet version=""1.0"" xmlns:xsl=""http://www.w3.org/1999/XSL/Transform""><xsl:output method=""xml"" indent=""yes"" encoding=""UTF-8""/><xsl:template match=""@*|node()""><xsl:copy>`n<xsl:apply-templates select=""@*|node()""/><xsl:for-each select=""@*""><xsl:text></xsl:text></xsl:for-each></xsl:copy>`n</xsl:template>`n</xsl:stylesheet>"),style:=null
		this.XML.TransformNodeToObject(xsl,this.xml)
	}Under(under,node,att:="",text:="",list:=""){
		new:=under.AppendChild(this.XML.CreateElement(node)),new.text:=text
		for a,b in att
			new.SetAttribute(a,b)
		for a,b in StrSplit(list,",")
			new.SetAttribute(b,att[b])
		return new
	}
}SSN(node,XPath){
	return node.SelectSingleNode(XPath)
}SN(node,XPath){
	return node.SelectNodes(XPath)
}m(x*){
	active:=WinActive("A")
	ControlGetFocus,Focus,A
	ControlGet,hwnd,hwnd,,%Focus%,ahk_id%active%
	static list:={btn:{oc:1,ari:2,ync:3,yn:4,rc:5,ctc:6},ico:{"x":16,"?":32,"!":48,"i":64}},msg:=[],msgbox
	list.title:="XML Class",list.def:=0,list.time:=0,value:=0,msgbox:=1,txt:=""
	for a,b in x
		obj:=StrSplit(b,":"),(vv:=List[obj.1,obj.2])?(value+=vv):(list[obj.1]!="")?(List[obj.1]:=obj.2):txt.=b "`n"
	msg:={option:value+262144+(list.def?(list.def-1)*256:0),title:list.title,time:list.time,txt:txt}
	Sleep,120
	MsgBox,% msg.option,% msg.title,% msg.txt,% msg.time
	msgbox:=0
	for a,b in {OK:value?"OK":"",Yes:"YES",No:"NO",Cancel:"CANCEL",Retry:"RETRY"}
		IfMsgBox,%a%
	{
		WinActivate,ahk_id%active%
		ControlFocus,%Focus%,ahk_id%active%
		return b
	}
}
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: 562
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

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<DTMCatalogueFile xmlns="http://tempuri.org/XMLSchema.xsd">
  <DTMCatalogue DTMCatalogue="">
    <DTMCatalogDataset xmlns="http://tempuri.org/DTMCatalogDataset.xsd">
      <DTMVendor d2p1:Name="Schneider Electric" xmlns:d2p1="http://tempuri.org/DTMCatalogDataset.xsd" />
      <DTMVendor d2p1:Name="Endress+Hauser" xmlns:d2p1="http://tempuri.org/DTMCatalogDataset.xsd" />
      <DTMVendor d2p1:Name="CodeWrights" xmlns:d2p1="http://tempuri.org/DTMCatalogDataset.xsd" />
      <DTMInfo d2p1:DTMID="0" d2p1:Name="PRM Comm DTM" d2p1:Version="1.1.1.0" d2p1:Date="2010-07-02" d2p1:Vendor="Schneider Electric" d2p1:ProgID="Se_CommPrmDtm.DTMCore" xmlns:d2p1="http://tempuri.org/DTMCatalogDataset.xsd">
        <FDTXML><FDTVersion major="1" minor="2" release="1" build="0" xmlns="x-schema:DTMInformationSchema.xml" /><fdt:VersionInformation name="PRM Comm DTM" version="1.1.1.0" vendor="Schneider Electric" date="2010-07-02" xmlns:fdt="x-schema:FDTDataTypesSchema.xml" /><DtmSchemaPaths xmlns="x-schema:DTMInformationSchema.xml"><DtmSchemaPath fdt:busCategory="036D1499-387B-11D4-86E1-00E0987270B9" fdt:path="C:\Program Files\Schneider Electric\PRM comm DTM\Profibus DPV1 Schema" xmlns:fdt="x-schema:FDTDataTypesSchema.xml" /></DtmSchemaPaths><DtmDeviceTypes xmlns="x-schema:DTMInformationSchema.xml"><fdt:DtmDeviceType classificationId="dtmSpecific" deviceTypeInformation=";********************************************************************************&#xD;&#xA;;* Vendor:	     Schneider Electric											           				      *&#xD;&#xA;;* Manufacturer: Schneider Electric (ID297)     													      *&#xD;&#xA;;*                                                													    *&#xD;&#xA;;* ============================================================================ *&#xD;&#xA;;*                                                                              *&#xD;&#xA;;* Model: 		   TCSEGPA23Fl4F	/ 	TCSEGPA23Fl4FK														  *&#xD;&#xA;;* Description: 	 Profibus Remote Master (PRM)                        				  *&#xD;&#xA;;* Family: 		   Modicon M340, Premium and Quantum ranges										    *&#xD;&#xA;;*																					  												          *&#xD;&#xA;;*                                                                              *&#xD;&#xA;;* Modification history:                                                        *&#xD;&#xA;;* ---------------------------------------------------------------------------- *&#xD;&#xA;;* 2009/11/24 [V1.00]  GSD file created 		               									    *&#xD;&#xA;;* 2010/04/28 [V1.01]  PNO certified GSD file version   				                *&#xD;&#xA;;*                                                                              *&#xD;&#xA;;* ============================================================================ *&#xD;&#xA;;********************************************************************************&#xD;&#xA;; &#xD;&#xA;;&#xD;&#xA;;&#xD;&#xA;;================================================================================&#xD;&#xA;;======= GENERAL DP KEYWORDS ====================================================&#xD;&#xA;;================================================================================&#xD;&#xA;&#xD;&#xA;#Profibus_DP&#xD;&#xA;GSD_Revision = 3&#xD;&#xA;&#xD;&#xA;Vendor_Name = "Schneider Electric"&#xD;&#xA;Model_Name = "TCSEGPA23Fl4F"&#xD;&#xA;Revision = "Rev 1.0"&#xD;&#xA;Ident_Number = 0x0C34&#xD;&#xA;Protocol_Ident = 0&#xD;&#xA;Station_Type = 1&#xD;&#xA;FMS_Supp = 0&#xD;&#xA;Hardware_Release = "1.x"&#xD;&#xA;Software_Release = "1.0"&#xD;&#xA;&#xD;&#xA;Max_Slaves_Supp = 125&#xD;&#xA;LAS_Len = 127&#xD;&#xA;Master_Freeze_Mode_supp=1&#xD;&#xA;Master_Sync_Mode_supp=1&#xD;&#xA;Master_Fail_Safe_supp=1&#xD;&#xA;&#xD;&#xA;&#xD;&#xA;; Supported hardware features&#xD;&#xA;Redundancy = 0&#xD;&#xA;Repeater_Ctrl_Sig = 2&#xD;&#xA;24V_Pins = 0&#xD;&#xA;&#xD;&#xA;&#xD;&#xA;;================================================================================&#xD;&#xA;;======= CLASS 1 MASTER SPECIFIC ================================================&#xD;&#xA;;================================================================================&#xD;&#xA;DPV1_Master=1&#xD;&#xA;C1_Master_Read_Write_supp=1&#xD;&#xA;Download_Supp = 0&#xD;&#xA;Upload_Supp = 0&#xD;&#xA;Act_Para_Brct_Supp = 0&#xD;&#xA;Act_Param_Supp = 0&#xD;&#xA;Max_MPS_Length = 60000&#xD;&#xA;Max_Lsdu_MS = 244&#xD;&#xA;Max_Lsdu_MM = 244&#xD;&#xA;Min_Poll_Timeout = 400&#xD;&#xA;DPV1_Conformance_Class = 1&#xD;&#xA;&#xD;&#xA;;================================================================================&#xD;&#xA;;======= SUPPORTED BAUDRATES ====================================================&#xD;&#xA;;================================================================================&#xD;&#xA;9.6_supp=1&#xD;&#xA;19.2_supp = 1&#xD;&#xA;31.25_supp = 1&#xD;&#xA;45.45_supp = 1&#xD;&#xA;93.75_supp = 1&#xD;&#xA;187.5_supp = 1&#xD;&#xA;500_supp = 1&#xD;&#xA;1.5M_supp = 1&#xD;&#xA;3M_supp = 1&#xD;&#xA;6M_supp = 1&#xD;&#xA;12M_supp = 1&#xD;&#xA;&#xD;&#xA;;================================================================================&#xD;&#xA;;======= MAXIMUM RESPONDER TIME FOR SUPPORTED BAUDRATES =========================&#xD;&#xA;;================================================================================&#xD;&#xA;MaxTsdr_9.6 = 60&#xD;&#xA;MaxTsdr_19.2 = 60&#xD;&#xA;MaxTsdr_31.25 = 60&#xD;&#xA;MaxTsdr_45.45 = 60&#xD;&#xA;MaxTsdr_93.75 = 60&#xD;&#xA;MaxTsdr_187.5 = 60&#xD;&#xA;MaxTsdr_500 = 100&#xD;&#xA;MaxTsdr_1.5M = 150&#xD;&#xA;MaxTsdr_3M = 250&#xD;&#xA;MaxTsdr_6M = 450&#xD;&#xA;MaxTsdr_12M = 800&#xD;&#xA;&#xD;&#xA;; Setup time for supported baudrates&#xD;&#xA;Tset_9.6 = 1&#xD;&#xA;Tset_19.2 = 1&#xD;&#xA;Tset_31.25 = 1&#xD;&#xA;Tset_45.45 = 1&#xD;&#xA;Tset_93.75 = 1&#xD;&#xA;Tset_187.5 = 1&#xD;&#xA;Tset_500 = 1&#xD;&#xA;Tset_1.5M = 1&#xD;&#xA;Tset_3M = 4&#xD;&#xA;Tset_6M = 8&#xD;&#xA;Tset_12M = 16&#xD;&#xA;&#xD;&#xA;; Bus parameter timers for supported baudrates&#xD;&#xA;Trdy_9.6 = 11&#xD;&#xA;Trdy_19.2 = 11&#xD;&#xA;Trdy_31.25 = 11&#xD;&#xA;Trdy_45.45 = 11&#xD;&#xA;Trdy_93.75 = 11&#xD;&#xA;Trdy_187.5 = 11&#xD;&#xA;Trdy_500 = 11&#xD;&#xA;Trdy_1.5M = 11&#xD;&#xA;Trdy_3M = 11&#xD;&#xA;Trdy_6M = 11&#xD;&#xA;Trdy_12M = 11&#xD;&#xA;&#xD;&#xA;Tsdi_9.6 = 70&#xD;&#xA;Tsdi_19.2 = 70&#xD;&#xA;Tsdi_31.25 = 70&#xD;&#xA;Tsdi_45.45 = 70&#xD;&#xA;Tsdi_93.75 = 70&#xD;&#xA;Tsdi_187.5 = 70&#xD;&#xA;Tsdi_500 = 150&#xD;&#xA;Tsdi_1.5M = 200&#xD;&#xA;Tsdi_3M = 250&#xD;&#xA;Tsdi_6M = 450&#xD;&#xA;Tsdi_12M = 800&#xD;&#xA;&#xD;&#xA;&#xD;&#xA;Tqui_9.6 = 0&#xD;&#xA;Tqui_19.2 = 0&#xD;&#xA;Tqui_31.25 = 0&#xD;&#xA;Tqui_45.45 = 0&#xD;&#xA;Tqui_93.75 = 0&#xD;&#xA;Tqui_187.5 = 0&#xD;&#xA;Tqui_500 = 0&#xD;&#xA;Tqui_1.5M = 0&#xD;&#xA;Tqui_3M = 3&#xD;&#xA;Tqui_6M = 6&#xD;&#xA;Tqui_12M = 9&#xD;&#xA;&#xD;&#xA;&#xD;&#xA;&#xD;&#xA;&#xD;&#xA;&#xD;&#xA;&#xD;&#xA;&#xD;&#xA;&#xD;&#xA;&#xD;&#xA;&#xD;&#xA;&#xD;&#xA;" dtmDevTypeID="DDF8883E-14A0-4659-B32F-FDC69D5BCA2D" dtmDevTypeIDVersion="1" deviceTypeInformationPath="C:\Program Files\Schneider Electric\PRM comm DTM\GSD\SE100C34.GSD" xmlns:fdt="x-schema:FDTDataTypesSchema.xml"><fdt:VersionInformation name="PRM Comm" vendor="Schneider Electric" version="1.x" date="" /><fdt:SupportedLanguages><fdt:LanguageId languageId="1033" /><fdt:LanguageId languageId="1031" /><fdt:LanguageId languageId="1034" /><fdt:LanguageId languageId="1036" /><fdt:LanguageId languageId="1040" /><fdt:LanguageId languageId="2052" /></fdt:SupportedLanguages><fdt:BusCategories><fdt:BusCategory busCategory="036D1499-387B-11D4-86E1-00E0987270B9" busCategoryName="Profibus DP/V1"><fdt:CommunicationTypeEntry communicationType="supported" /></fdt:BusCategory></fdt:BusCategories><fdt:DeviceIcon path="C:\Program Files\Schneider Electric\PRM comm DTM\Images\schneider.ico" /></fdt:DtmDeviceType></DtmDeviceTypes></FDTXML>
        <DeviceType d2p1:DeviceTypeID="0" d2p1:Name="PRM Comm" d2p1:Version="1.x" d2p1:Date="" d2p1:Vendor="Schneider Electric" d2p1:Classification="dtmSpecific" d2p1:Type="communication" d2p1:ID="DDF8883E-14A0-4659-B32F-FDC69D5BCA2D" d2p1:IDVersion="1">
          <FDTXML><fdt:DtmDeviceType classificationId="dtmSpecific" deviceTypeInformation=";********************************************************************************&#xD;&#xA;;* Vendor:	     Schneider Electric											           				      *&#xD;&#xA;;* Manufacturer: Schneider Electric (ID297)     													      *&#xD;&#xA;;*                                                													    *&#xD;&#xA;;* ============================================================================ *&#xD;&#xA;;*                                                                              *&#xD;&#xA;;* Model: 		   TCSEGPA23Fl4F	/ 	TCSEGPA23Fl4FK														  *&#xD;&#xA;;* Description: 	 Profibus Remote Master (PRM)                        				  *&#xD;&#xA;;* Family: 		   Modicon M340, Premium and Quantum ranges										    *&#xD;&#xA;;*																					  												          *&#xD;&#xA;;*                                                                              *&#xD;&#xA;;* Modification history:                                                        *&#xD;&#xA;;* ---------------------------------------------------------------------------- *&#xD;&#xA;;* 2009/11/24 [V1.00]  GSD file created 		               									    *&#xD;&#xA;;* 2010/04/28 [V1.01]  PNO certified GSD file version   				                *&#xD;&#xA;;*                                                                              *&#xD;&#xA;;* ============================================================================ *&#xD;&#xA;;********************************************************************************&#xD;&#xA;; &#xD;&#xA;;&#xD;&#xA;;&#xD;&#xA;;================================================================================&#xD;&#xA;;======= GENERAL DP KEYWORDS ====================================================&#xD;&#xA;;================================================================================&#xD;&#xA;&#xD;&#xA;#Profibus_DP&#xD;&#xA;GSD_Revision = 3&#xD;&#xA;&#xD;&#xA;Vendor_Name = "Schneider Electric"&#xD;&#xA;Model_Name = "TCSEGPA23Fl4F"&#xD;&#xA;Revision = "Rev 1.0"&#xD;&#xA;Ident_Number = 0x0C34&#xD;&#xA;Protocol_Ident = 0&#xD;&#xA;Station_Type = 1&#xD;&#xA;FMS_Supp = 0&#xD;&#xA;Hardware_Release = "1.x"&#xD;&#xA;Software_Release = "1.0"&#xD;&#xA;&#xD;&#xA;Max_Slaves_Supp = 125&#xD;&#xA;LAS_Len = 127&#xD;&#xA;Master_Freeze_Mode_supp=1&#xD;&#xA;Master_Sync_Mode_supp=1&#xD;&#xA;Master_Fail_Safe_supp=1&#xD;&#xA;&#xD;&#xA;&#xD;&#xA;; Supported hardware features&#xD;&#xA;Redundancy = 0&#xD;&#xA;Repeater_Ctrl_Sig = 2&#xD;&#xA;24V_Pins = 0&#xD;&#xA;&#xD;&#xA;&#xD;&#xA;;================================================================================&#xD;&#xA;;======= CLASS 1 MASTER SPECIFIC ================================================&#xD;&#xA;;================================================================================&#xD;&#xA;DPV1_Master=1&#xD;&#xA;C1_Master_Read_Write_supp=1&#xD;&#xA;Download_Supp = 0&#xD;&#xA;Upload_Supp = 0&#xD;&#xA;Act_Para_Brct_Supp = 0&#xD;&#xA;Act_Param_Supp = 0&#xD;&#xA;Max_MPS_Length = 60000&#xD;&#xA;Max_Lsdu_MS = 244&#xD;&#xA;Max_Lsdu_MM = 244&#xD;&#xA;Min_Poll_Timeout = 400&#xD;&#xA;DPV1_Conformance_Class = 1&#xD;&#xA;&#xD;&#xA;;================================================================================&#xD;&#xA;;======= SUPPORTED BAUDRATES ====================================================&#xD;&#xA;;================================================================================&#xD;&#xA;9.6_supp=1&#xD;&#xA;19.2_supp = 1&#xD;&#xA;31.25_supp = 1&#xD;&#xA;45.45_supp = 1&#xD;&#xA;93.75_supp = 1&#xD;&#xA;187.5_supp = 1&#xD;&#xA;500_supp = 1&#xD;&#xA;1.5M_supp = 1&#xD;&#xA;3M_supp = 1&#xD;&#xA;6M_supp = 1&#xD;&#xA;12M_supp = 1&#xD;&#xA;&#xD;&#xA;;================================================================================&#xD;&#xA;;======= MAXIMUM RESPONDER TIME FOR SUPPORTED BAUDRATES =========================&#xD;&#xA;;================================================================================&#xD;&#xA;MaxTsdr_9.6 = 60&#xD;&#xA;MaxTsdr_19.2 = 60&#xD;&#xA;MaxTsdr_31.25 = 60&#xD;&#xA;MaxTsdr_45.45 = 60&#xD;&#xA;MaxTsdr_93.75 = 60&#xD;&#xA;MaxTsdr_187.5 = 60&#xD;&#xA;MaxTsdr_500 = 100&#xD;&#xA;MaxTsdr_1.5M = 150&#xD;&#xA;MaxTsdr_3M = 250&#xD;&#xA;MaxTsdr_6M = 450&#xD;&#xA;MaxTsdr_12M = 800&#xD;&#xA;&#xD;&#xA;; Setup time for supported baudrates&#xD;&#xA;Tset_9.6 = 1&#xD;&#xA;Tset_19.2 = 1&#xD;&#xA;Tset_31.25 = 1&#xD;&#xA;Tset_45.45 = 1&#xD;&#xA;Tset_93.75 = 1&#xD;&#xA;Tset_187.5 = 1&#xD;&#xA;Tset_500 = 1&#xD;&#xA;Tset_1.5M = 1&#xD;&#xA;Tset_3M = 4&#xD;&#xA;Tset_6M = 8&#xD;&#xA;Tset_12M = 16&#xD;&#xA;&#xD;&#xA;; Bus parameter timers for supported baudrates&#xD;&#xA;Trdy_9.6 = 11&#xD;&#xA;Trdy_19.2 = 11&#xD;&#xA;Trdy_31.25 = 11&#xD;&#xA;Trdy_45.45 = 11&#xD;&#xA;Trdy_93.75 = 11&#xD;&#xA;Trdy_187.5 = 11&#xD;&#xA;Trdy_500 = 11&#xD;&#xA;Trdy_1.5M = 11&#xD;&#xA;Trdy_3M = 11&#xD;&#xA;Trdy_6M = 11&#xD;&#xA;Trdy_12M = 11&#xD;&#xA;&#xD;&#xA;Tsdi_9.6 = 70&#xD;&#xA;Tsdi_19.2 = 70&#xD;&#xA;Tsdi_31.25 = 70&#xD;&#xA;Tsdi_45.45 = 70&#xD;&#xA;Tsdi_93.75 = 70&#xD;&#xA;Tsdi_187.5 = 70&#xD;&#xA;Tsdi_500 = 150&#xD;&#xA;Tsdi_1.5M = 200&#xD;&#xA;Tsdi_3M = 250&#xD;&#xA;Tsdi_6M = 450&#xD;&#xA;Tsdi_12M = 800&#xD;&#xA;&#xD;&#xA;&#xD;&#xA;Tqui_9.6 = 0&#xD;&#xA;Tqui_19.2 = 0&#xD;&#xA;Tqui_31.25 = 0&#xD;&#xA;Tqui_45.45 = 0&#xD;&#xA;Tqui_93.75 = 0&#xD;&#xA;Tqui_187.5 = 0&#xD;&#xA;Tqui_500 = 0&#xD;&#xA;Tqui_1.5M = 0&#xD;&#xA;Tqui_3M = 3&#xD;&#xA;Tqui_6M = 6&#xD;&#xA;Tqui_12M = 9&#xD;&#xA;&#xD;&#xA;&#xD;&#xA;&#xD;&#xA;&#xD;&#xA;&#xD;&#xA;&#xD;&#xA;&#xD;&#xA;&#xD;&#xA;&#xD;&#xA;&#xD;&#xA;&#xD;&#xA;" dtmDevTypeID="DDF8883E-14A0-4659-B32F-FDC69D5BCA2D" dtmDevTypeIDVersion="1" deviceTypeInformationPath="C:\Program Files\Schneider Electric\PRM comm DTM\GSD\SE100C34.GSD" xmlns:fdt="x-schema:FDTDataTypesSchema.xml"><fdt:VersionInformation name="PRM Comm" vendor="Schneider Electric" version="1.x" date="" /><fdt:SupportedLanguages><fdt:LanguageId languageId="1033" /><fdt:LanguageId languageId="1031" /><fdt:LanguageId languageId="1034" /><fdt:LanguageId languageId="1036" /><fdt:LanguageId languageId="1040" /><fdt:LanguageId languageId="2052" /></fdt:SupportedLanguages><fdt:BusCategories><fdt:BusCategory busCategory="036D1499-387B-11D4-86E1-00E0987270B9" busCategoryName="Profibus DP/V1"><fdt:CommunicationTypeEntry communicationType="supported" /></fdt:BusCategory></fdt:BusCategories><fdt:DeviceIcon path="C:\Program Files\Schneider Electric\PRM comm DTM\Images\schneider.ico" /></fdt:DtmDeviceType></FDTXML>
          <DeviceIcon>C:\Program Files\Schneider Electric\PRM comm DTM\Images\schneider.ico</DeviceIcon>
          <DeviceIdentification d2p1:DeviceTypeID="0C34" d2p1:SubDeviceType="" d2p1:ManufacturerID="" d2p1:Information=";********************************************************************************&#xD;&#xA;;* Vendor:	     Schneider Electric											           				      *&#xD;&#xA;;* Manufacturer: Schneider Electric (ID297)     													      *&#xD;&#xA;;*                                                													    *&#xD;&#xA;;* ============================================================================ *&#xD;&#xA;;*                                                                              *&#xD;&#xA;;* Model: 		   TCSEGPA23Fl4F	/ 	TCSEGPA23Fl4FK														  *&#xD;&#xA;;* Description: 	 Profibus Remote Master (PRM)                        				  *&#xD;&#xA;;* Family: 		   Modicon M340, Premium and Quantum ranges										    *&#xD;&#xA;;*																					  												          *&#xD;&#xA;;*                                                                              *&#xD;&#xA;;* Modification history:                                                        *&#xD;&#xA;;* ---------------------------------------------------------------------------- *&#xD;&#xA;;* 2009/11/24 [V1.00]  GSD file created 		               									    *&#xD;&#xA;;* 2010/04/28 [V1.01]  PNO certified GSD file version   				                *&#xD;&#xA;;*                                                                              *&#xD;&#xA;;* ============================================================================ *&#xD;&#xA;;********************************************************************************&#xD;&#xA;; &#xD;&#xA;;&#xD;&#xA;;&#xD;&#xA;;================================================================================&#xD;&#xA;;======= GENERAL DP KEYWORDS ====================================================&#xD;&#xA;;================================================================================&#xD;&#xA;&#xD;&#xA;#Profibus_DP&#xD;&#xA;GSD_Revision = 3&#xD;&#xA;&#xD;&#xA;Vendor_Name = "Schneider Electric"&#xD;&#xA;Model_Name = "TCSEGPA23Fl4F"&#xD;&#xA;Revision = "Rev 1.0"&#xD;&#xA;Ident_Number = 0x0C34&#xD;&#xA;Protocol_Ident = 0&#xD;&#xA;Station_Type = 1&#xD;&#xA;FMS_Supp = 0&#xD;&#xA;Hardware_Release = "1.x"&#xD;&#xA;Software_Release = "1.0"&#xD;&#xA;&#xD;&#xA;Max_Slaves_Supp = 125&#xD;&#xA;LAS_Len = 127&#xD;&#xA;Master_Freeze_Mode_supp=1&#xD;&#xA;Master_Sync_Mode_supp=1&#xD;&#xA;Master_Fail_Safe_supp=1&#xD;&#xA;&#xD;&#xA;&#xD;&#xA;; Supported hardware features&#xD;&#xA;Redundancy = 0&#xD;&#xA;Repeater_Ctrl_Sig = 2&#xD;&#xA;24V_Pins = 0&#xD;&#xA;&#xD;&#xA;&#xD;&#xA;;================================================================================&#xD;&#xA;;======= CLASS 1 MASTER SPECIFIC ================================================&#xD;&#xA;;================================================================================&#xD;&#xA;DPV1_Master=1&#xD;&#xA;C1_Master_Read_Write_supp=1&#xD;&#xA;Download_Supp = 0&#xD;&#xA;Upload_Supp = 0&#xD;&#xA;Act_Para_Brct_Supp = 0&#xD;&#xA;Act_Param_Supp = 0&#xD;&#xA;Max_MPS_Length = 60000&#xD;&#xA;Max_Lsdu_MS = 244&#xD;&#xA;Max_Lsdu_MM = 244&#xD;&#xA;Min_Poll_Timeout = 400&#xD;&#xA;DPV1_Conformance_Class = 1&#xD;&#xA;&#xD;&#xA;;================================================================================&#xD;&#xA;;======= SUPPORTED BAUDRATES ====================================================&#xD;&#xA;;================================================================================&#xD;&#xA;9.6_supp=1&#xD;&#xA;19.2_supp = 1&#xD;&#xA;31.25_supp = 1&#xD;&#xA;45.45_supp = 1&#xD;&#xA;93.75_supp = 1&#xD;&#xA;187.5_supp = 1&#xD;&#xA;500_supp = 1&#xD;&#xA;1.5M_supp = 1&#xD;&#xA;3M_supp = 1&#xD;&#xA;6M_supp = 1&#xD;&#xA;12M_supp = 1&#xD;&#xA;&#xD;&#xA;;================================================================================&#xD;&#xA;;======= MAXIMUM RESPONDER TIME FOR SUPPORTED BAUDRATES =========================&#xD;&#xA;;================================================================================&#xD;&#xA;MaxTsdr_9.6 = 60&#xD;&#xA;MaxTsdr_19.2 = 60&#xD;&#xA;MaxTsdr_31.25 = 60&#xD;&#xA;MaxTsdr_45.45 = 60&#xD;&#xA;MaxTsdr_93.75 = 60&#xD;&#xA;MaxTsdr_187.5 = 60&#xD;&#xA;MaxTsdr_500 = 100&#xD;&#xA;MaxTsdr_1.5M = 150&#xD;&#xA;MaxTsdr_3M = 250&#xD;&#xA;MaxTsdr_6M = 450&#xD;&#xA;MaxTsdr_12M = 800&#xD;&#xA;&#xD;&#xA;; Setup time for supported baudrates&#xD;&#xA;Tset_9.6 = 1&#xD;&#xA;Tset_19.2 = 1&#xD;&#xA;Tset_31.25 = 1&#xD;&#xA;Tset_45.45 = 1&#xD;&#xA;Tset_93.75 = 1&#xD;&#xA;Tset_187.5 = 1&#xD;&#xA;Tset_500 = 1&#xD;&#xA;Tset_1.5M = 1&#xD;&#xA;Tset_3M = 4&#xD;&#xA;Tset_6M = 8&#xD;&#xA;Tset_12M = 16&#xD;&#xA;&#xD;&#xA;; Bus parameter timers for supported baudrates&#xD;&#xA;Trdy_9.6 = 11&#xD;&#xA;Trdy_19.2 = 11&#xD;&#xA;Trdy_31.25 = 11&#xD;&#xA;Trdy_45.45 = 11&#xD;&#xA;Trdy_93.75 = 11&#xD;&#xA;Trdy_187.5 = 11&#xD;&#xA;Trdy_500 = 11&#xD;&#xA;Trdy_1.5M = 11&#xD;&#xA;Trdy_3M = 11&#xD;&#xA;Trdy_6M = 11&#xD;&#xA;Trdy_12M = 11&#xD;&#xA;&#xD;&#xA;Tsdi_9.6 = 70&#xD;&#xA;Tsdi_19.2 = 70&#xD;&#xA;Tsdi_31.25 = 70&#xD;&#xA;Tsdi_45.45 = 70&#xD;&#xA;Tsdi_93.75 = 70&#xD;&#xA;Tsdi_187.5 = 70&#xD;&#xA;Tsdi_500 = 150&#xD;&#xA;Tsdi_1.5M = 200&#xD;&#xA;Tsdi_3M = 250&#xD;&#xA;Tsdi_6M = 450&#xD;&#xA;Tsdi_12M = 800&#xD;&#xA;&#xD;&#xA;&#xD;&#xA;Tqui_9.6 = 0&#xD;&#xA;Tqui_19.2 = 0&#xD;&#xA;Tqui_31.25 = 0&#xD;&#xA;Tqui_45.45 = 0&#xD;&#xA;Tqui_93.75 = 0&#xD;&#xA;Tqui_187.5 = 0&#xD;&#xA;Tqui_500 = 0&#xD;&#xA;Tqui_1.5M = 0&#xD;&#xA;Tqui_3M = 3&#xD;&#xA;Tqui_6M = 6&#xD;&#xA;Tqui_12M = 9&#xD;&#xA;&#xD;&#xA;&#xD;&#xA;&#xD;&#xA;&#xD;&#xA;&#xD;&#xA;&#xD;&#xA;&#xD;&#xA;&#xD;&#xA;&#xD;&#xA;&#xD;&#xA;&#xD;&#xA;" d2p1:SoftwareRevisionID="" d2p1:HardwareRevisionID="" d2p1:DTMSupportLevelID="genericSupport" d2p1:BusProtocolID="protocol_DP" d2p1:BusProtocolVersionID="" d2p1:FDTXML="<?xml version='1.0' ?><FDT xmlns='x-schema:DTMDeviceTypeIdentSchema.xml' xmlns:ident='x-schema:DTMIdentSchema.xml' xmlns:fdt='x-schema:FDTDataTypesSchema.xml'>  <DeviceIdentifications>    <DeviceIdentification ident:idDTMSupportLevel='genericSupport' xmlns:ident='x-schema:DTMIdentSchema.xml'>      <IdBusProtocol ident:protocolSpecificName='Profibus DP' ident:value='protocol_DP'/>      <IdBusProtocolVersion ident:protocolSpecificName='not applicable'/>      <IdManufacturer ident:protocolSpecificName='Schneider Electric'/>      <IdTypeID ident:protocolSpecificName='IDENT_NUMBER' ident:value='0C34'/>      <IdSoftwareRevision ident:protocolSpecificName='not applicable'/>      <IdHardwareRevision ident:protocolSpecificName='not applicable'/>    </DeviceIdentification>  </DeviceIdentifications></FDT>" d2p1:ProtocolID="036D1499-387B-11D4-86E1-00E0987270B9" />
         
So I use the following code:

Code: Select all

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: 738
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

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

mytext:=""
IfExist, %DTMCatalog%
{
	FileRead, xmlcontents, %DTMCatalog%
	NewXML:=New XML("xml")
	NewXML.XML.LoadXML(xmlcontents)
	NewXML.Language()
	list:=NewXML.SN("//DTMInfo")
	while (DTMInfo:=list.item[a_index-1]) 
	{

		DTMInfo_version:=NewXML.SSN("/DTMCatalogueFile/DTMCatalogue/DTMCatalogDataset/DTMInfo[" a_index-1 "]/@d2p1:Version").text
		DTMInfo_name:=NewXML.SSN("/DTMCatalogueFile/DTMCatalogue/DTMCatalogDataset/DTMInfo[" a_index-1 "]/@d2p1:Name").text
		mytext:=mytext "DTM " a_index " name: " DTMInfo_name ", version: " DTMInfo_version "`n"
	}
}
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 51 times
User avatar
maestrith
Posts: 738
Joined: 16 Oct 2013, 13:52

Re: XML Class

10 Jul 2017, 10:54

Code: Select all

mytext:=""
IfExist,DTMCatalog_2.xml
{
	FileRead, xmlcontents,DTMCatalog_2.xml
	NewXML:=New XML("xml")
	NewXML.XML.LoadXML(xmlcontents)
	NewXML.Language()
	list:=NewXML.SN("//DTMInfo")
	while (DTMInfo:=list.item[a_index-1]) 
	{
		/*
			DTMInfo_version:=NewXML.SSN("/DTMCatalogueFile/DTMCatalogue/DTMCatalogDataset/DTMInfo[" a_index-1 "]/@d2p1:Version").text
		*/
		DTMInfo_Version:=SSN(DTMInfo,"@d2p1:Version").text
		/*
			DTMInfo_name:=NewXML.SSN("/DTMCatalogueFile/DTMCatalogue/DTMCatalogDataset/DTMInfo[" a_index-1 "]/@d2p1:Name").text
		*/
		DTMInfo_name:=SSN(DTMInfo,"@d2p1:Name").text
		mytext:=mytext "DTM " a_index " name: " DTMInfo_name ", version: " DTMInfo_version "`n"
	}
}
m(mytext)
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: 639
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.
User avatar
Joe Glines
Posts: 562
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

11 Oct 2018, 13:22

Jean was wanting to play with Maestrith's XML Class. I wanted to learn a bit more so we had a working session reviewing the XML Class and XPATH. I hope it helps... :lol:
User avatar
maestrith
Posts: 738
Joined: 16 Oct 2013, 13:52

Re: XML Class

11 Oct 2018, 13:26

Oh lord...if you want to see me mess up royal, give it a watch....
AHK Studio OSD GUI Creator
Donations
Discord
All code is done on a Windows 10 PC Running x64 and AutoHotkey x32

Return to “AHK Studio”

Who is online

Users browsing this forum: No registered users and 1 guest