Here's the code I used to get the macro XML as a string (which could then be written out to a file):
MacroCommand macro = your_macro; // specify the macro to save to XML
MemoryStream memoryStream = new MemoryStream();
XmlTextWriter w = new XmlTextWriter(memoryStream, System.Text.Encoding.Unicode);
macro.WriteToXml(w);
w.Flush();
memoryStream.Position = 0;
StreamReader r = new StreamReader(memoryStream, System.Text.Encoding.Unicode);
string xmlOutput = r.ReadToEnd(); // Here's your XML text
w.Close();
r.Close();
memoryStream = null;
Likewise... here's the code I used to load a macro from an XML string
string xmlText = your_macro_xml_data; // specify the XML text
MemoryStream memoryStream = new MemoryStream();
StreamWriter w = new StreamWriter(memoryStream, System.Text.Encoding.Unicode);
w.Write(xmlText);
w.Flush();
memoryStream.Position = 0;
XmlTextReader r = new XmlTextReader(memoryStream);
MacroCommand macro = new MacroCommand();
macro.ReadFromXml(r);
w.Close();
r.Close();
memoryStream = null;
This was my first attempt at using MemoryStream or XmlTextReader, so there are likely more efficient ways to do this. I welcome any comments.
[Modified at 10/27/2005 07:39 AM]