C# 请参阅:C# 用 System.Xml 读 Freeplane.mm文件,生成测试用例.csv文件
Freeplane 是一款基于 Java 的开源软件,继承 Freemind 的思维导图工具软件,它扩展了知识管理功能,在 Freemind 上增加了一些额外的功能,比如数学公式、节点属性面板等。
打开 lazarus-IDE,创建 project: xml2csv , 编辑GUI界面,编写 unit1.pas 如下
unit Unit1;{$mode objfpc}{$H+}interfaceusesClasses, SysUtils, Forms, Controls, Graphics, Dialogs,StdCtrls, Crt, laz2_DOM, laz2_XMLRead; // ShellApi,type{ TForm1 }TForm1 = class(TForm)Button1: TButton;Button2: TButton;Edit1: TEdit;Memo1: TMemo;OpenDialog1: TOpenDialog;procedure Button1Click(Sender: TObject);procedure Button2Click(Sender: TObject);privatepublicend;varForm1: TForm1;fn1: String;fn2: String;xmlDoc: TXMLDocument;sList: TStringList;implementation{$R *.lfm}{ TForm1 }procedure TForm1.Button1Click(Sender: TObject);// Local function that outputs a node attributes as a stringfunction GetNodeAttribute(pNode: TDOMNode; attr: string):string;var i: integer;beginResult:='';if pNode.HasAttributes thenfor i := 0 to pNode.Attributes.Length -1 dowith pNode.Attributes[i] doif NodeName = attr thenResult := format('%s', [NodeValue]);// Remove leading and trailing spacesResult:=Trim(Result);end;// Recursive function to process a node and all its child nodesprocedure ParseXML(Node:TDOMNode);var str: string;begin// Exit procedure if no more nodes to processif Node = nil then Exit;// Add a node 'TEXT' attributes to StringListstr := GetNodeAttribute(Node, 'TEXT');if str <>'' then sList.Add(str);// Process all child nodesNode := Node.FirstChild;while Node <> Nil dobeginParseXML(Node);Node := Node.NextSibling;end;end;beginif OpenDialog1.Execute thenbeginfn1 := OpenDialog1.FileName;Edit1.Clear;Edit1.Text := fn1;end;if FileExists(fn1) thenbegin//Memo1.Lines.LoadFromFile(fn1);trysList := TStringList.Create;ReadXMLFile(xmlDoc, fn1);Memo1.Lines.Clear;ParseXML(xmlDoc.DocumentElement);Memo1.Lines.Add(sList.Text);finallyxmlDoc.Free;sList.Free;end;endelseShowMessage(AnsiToUTF8(fn1+' 文件没找到'));end;procedure TForm1.Button2Click(Sender: TObject);
beginfn1 := Edit1.Text;if FileExists(fn1) thenbegin// Simple one-liner (ignoring error returns) ://if ShellExecute(0,nil, PChar('mm_Xml_csv.exe'),PChar(fn1),nil,1) =0 then;SysUtils.ExecuteProcess('mm_Xml_csv.exe', Utf8ToAnsi(fn1), []);delay(100);endelseShowMessage(AnsiToUTF8(fn1+' 文件没找到'));fn2 := fn1 +'.csv';if FileExists(fn2) thenbeginMemo1.Lines.LoadFromFile(fn2);end;
end;end.
copy mm_Xml_csv.exe to projects\xml2csv\ 点击运行。
注意有中文文件名,需用 SysUtils.ExecuteProcess('mm_Xml_csv.exe', Utf8ToAnsi(fn1), []);
参阅:Executing External Programs