Hello Guest it is April 18, 2024, 02:47:47 AM

Author Topic: XML file reader  (Read 6313 times)

0 Members and 1 Guest are viewing this topic.

Offline geast

*
  •  50 50
    • View Profile
XML file reader
« 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.

Offline BR549

*
  •  6,965 6,965
    • View Profile
Re: XML file reader
« Reply #1 on: January 26, 2013, 07:43:20 PM »
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

Offline geast

*
  •  50 50
    • View Profile
Re: XML file reader
« Reply #2 on: January 27, 2013, 03:57:41 AM »
I don't want to mess with Mach's xml, but a *.xml file which stores plasma cutting parameters.

Offline stirling

*
  • *
  •  2,188 2,188
  • UK
    • View Profile
    • www.razordance.co.uk
Re: XML file reader
« Reply #3 on: January 27, 2013, 06:24:50 AM »
Sure, CB supports DLL access so just create your XML DOM as per normal and you're "good to go".

Ian

Offline geast

*
  •  50 50
    • View Profile
Re: XML file reader
« Reply #4 on: January 27, 2013, 07:48:29 AM »
Beacouse i'm not so experienced programmer, can you please give me some code example?

Offline stirling

*
  • *
  •  2,188 2,188
  • UK
    • View Profile
    • www.razordance.co.uk
Re: XML file reader
« Reply #5 on: January 27, 2013, 09:20:54 AM »
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

Offline geast

*
  •  50 50
    • View Profile
Re: XML file reader
« Reply #6 on: January 27, 2013, 12:59:37 PM »
Here is the file
Re: XML file reader
« Reply #7 on: January 27, 2013, 03:19:17 PM »

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.......

Offline geast

*
  •  50 50
    • View Profile
Re: XML file reader
« Reply #8 on: January 28, 2013, 12:58:07 AM »
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?

Offline stirling

*
  • *
  •  2,188 2,188
  • UK
    • View Profile
    • www.razordance.co.uk
Re: XML file reader
« Reply #9 on: January 28, 2013, 09:10:01 AM »
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.

Code: [Select]
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