Machsupport Forum
Mach Discussion => VB and the development of wizards => Topic started by: geast on January 26, 2013, 12:14:25 PM
-
Hello everyone.
I want to read some data stored in a *.xml file into some oemdro's, or other mach's variables, by using a macro.
Has anybody do it before?
I know there is the Msxml.dll from microsoft, is there any way to use in cypress vbscript language?
Any help will be appreciated.
-
NOT a good idea to mess with Machs XML.
Besides Most of the info in the XML will be in mach3 somewhere where you can access it with CB.
(;-) TP
-
I don't want to mess with Mach's xml, but a *.xml file which stores plasma cutting parameters.
-
Sure, CB supports DLL access so just create your XML DOM as per normal and you're "good to go".
Ian
-
Beacouse i'm not so experienced programmer, can you please give me some code example?
-
Can't give you an example without seeing the structure of the xml you want to parse - post it and I'll do you a starter.
Ian
-
Here is the file
-
It is easy. in the xlm file do a search for the variable name between < and >
then look for the same variable name between </ and >
the value is between the first and second finds.
For example OEMDRO131 = 4200 in string below.
.....OEMLED130><OEMDRO131>4200.</OEMDRO131><OEMLED13.......
-
Atlas56 thanks for the reply, but if you look in the xml file i post, how can i make i search? With the file I/O commands which the cypress basic supports, it would be very difficult to find the requested variables. Can you give me some code example?
-
Your XML is not particularly well structured (it way over uses attributes and unneccessarily uses different names for otherwise common elements) but here is a quicky example of iterating through each child (Row1, Row2 etc.) of the root node (Tabelle) and printing out the value of the "CNC_Speed" attribute of those child nodes.
Just copy it into the Mach CB editor, CHANGE the variable xmlFile TO THE FULL PATH/FILENAME OF YOUR XML and run. The values will display each second in the message DRO.
I've made no attempt at catching any errors so what you see is what you get :o.
Option Explicit
Dim xmlDoc, xmlFile, xmlRows, i
'create a DOM
Set xmlDoc = CreateObject("Microsoft.XMLDOM")
xmlDoc.async = "false"
'load the xml
xmlFile = "Plasma_Data.xml"
xmlDoc.load (xmlFile)
'get all the children of the Tabelle element i.e. all the Row1, Row2 etc. etc.
Set xmlRows = xmldoc.selectSingleNode("Tabelle").childNodes
'loop through them displaying the CNC_Speed attribute
For i=0 To xmlRows.length - 1
message xmlRows(i).getAttribute("CNC_Speed")
sleep 1000 'so we can see them displayed
Next
'tidy up
Set xmlRows = Nothing
Set xmlDoc = Nothing
To season to taste google "XML DOM using VBScript" or similar.
Cheers
Ian
-
It just works fine, it was exactly what i was looking for.
Thank's for all the help.You saved me alot of time, searching for the solution.
Thanks again stirling.
-
;D