25.6.5 Using the MSXML Parser to Convert an Origin Worksheet into an XML Document


Origin C's COM support can be used to programmatically create XML documents. To see what the code might look like, take a look at the WksToXML.PDF.

WKSTOXML.png

The functions in the program use the Microsoft MSXML parser (version 3 - other versions can be used) to convert an Origin worksheet into an XML document in the function called WksToXML. The function takes two arguments:

1. A string - This string defaults to Data1, but can be any worksheet name, including a LabTalk string variable (e.g. %H - the active window title). Using a LabTalk string variable would make it easier to perform a batch process where multiple worksheets are saved to XML files.
2. A string - This string defaults to the C drive (e.g. C:\), but can be any valid path.

Once the C file has been compiled in Code Builder (Origin's Integrated Development Environment), the WKSToXML function can be called using either Origin C or LabTalk syntax. The call would similar to the following:

In Origin C In LabTalk
WKSToXML(MyWorksheet,C:\Temp); WKSToXML MyWorksheet C:\Temp;

Another function in this file, XMLToWks, allows you to import an XML document into an Origin worksheet. The function takes one argument, the path and filename, as a string. A proper function call using this function would be as follows:

In Origin C In LabTalk
XMLToWks(C:\Temp); XMLToWks C:\Temp;

Note: This example is also available in the \Samples\COM Server and Client\XML\Client subfolder in Origin. It is called WksToXML.c.