C# 用 System.Xml 读 Freeplane.mm文件,生成测试用例.csv文件

Freeplane 是一款基于 Java 的开源软件,继承 Freemind 的思维导图工具软件,它扩展了知识管理功能,在 Freemind 上增加了一些额外的功能,比如数学公式、节点属性面板等。

编写 read_Xml.cs 如下

cs 复制代码
using System;
using System.IO;
using System.Text;
using System.Xml;

namespace Test
{
  public class ReadXml
  {    
    static void Main(string[] args)
    {
        if (args.Length <1){
            Console.WriteLine(" usage: read_Xml.exe your_file.mm ");
            return;
        }
        if (! File.Exists(args[0])){
            Console.WriteLine("Error: {0} not exists.", args[0]);
            return;
        }
        if (Path.GetExtension(args[0]) != ".mm"){
            Console.WriteLine("Tip: can only read file.mm");
        }
        string path1 = args[0]; // your_mm_file_path
        string path2 = path1 +".csv";
        FileStream fs = new FileStream(path2,FileMode.OpenOrCreate,FileAccess.Write);
        StreamWriter fsw = new StreamWriter(fs);
        fsw.WriteLine("应用系统名,用例编号,模块名,测试用例描述,正反向,执行步骤,预期结果");
        
        //定义几个变量
        string xt,zd1,zd2,zd3,zd4,zd5,zd6,txt,csylms;
        zd5 =""; zd6 ="";
        // 初始化一个 xmldoc实例
        XmlDocument xml = new XmlDocument();
        //XmlNodeList list1,list2,list3;
        // 导入指定的 xml文件
        xml.Load(path1);
        // 指定root节点
        XmlNode root = xml.SelectSingleNode("/map/node");
        xt = root.Attributes["TEXT"].Value;
        Console.WriteLine(xt);
        if (root.HasChildNodes){
          // 获取该节点下所有直接子节点
          //list1 = root.ChildNodes;
          foreach( XmlNode node1 in root.ChildNodes){
            if (node1.Name =="node"){
              zd1 = node1.Attributes["TEXT"].Value;
              //Console.WriteLine("  "+zd1);
              if (node1.HasChildNodes){
                //list2 = node1.ChildNodes;
                foreach( XmlNode node2 in node1.ChildNodes){
                  if (node2.Name =="node"){
                    zd2 = node2.Attributes["TEXT"].Value;
                    //Console.WriteLine("    "+zd2);
                    if (node2.HasChildNodes){
                      //list3 = node2.ChildNodes;
                      foreach( XmlNode node3 in node2.ChildNodes){
                        if (node3.Name =="node"){
                          zd3 = node3.Attributes["TEXT"].Value;
                          if (node3.HasChildNodes){
                            foreach( XmlNode node4 in node3.ChildNodes){
                              if (node4.Name =="node"){
                                zd4 = node4.Attributes["TEXT"].Value;
                                if (node4.HasChildNodes){
                                  foreach( XmlNode node5 in node4.ChildNodes){
                                    if (node5.Name =="node"){
                                      txt = node5.Attributes["TEXT"].Value;
                                      if (txt.StartsWith("步骤:")){
                                        zd5 = txt.Substring(3);
                                      } else if (txt.StartsWith("预期结果:")){
                                        zd6 = txt.Substring(5);
                                        csylms = zd2 +"-"+ zd4; //测试用例描述
                                        fsw.WriteLine("{0},{1},{2},{3},{4},{5}",xt,zd1,csylms,zd3,zd5,zd6);
                                      } else {
                                        zd5 =""; zd6 ="";
                                      }
                                    }
                                  }
                                }
                              }
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
        fsw.Flush();
        fsw.Close();
    }
  }
}

SET PATH=%PATH%;C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319;

编译 csc /t:exe read_Xml.cs

运行 read_Xml.exe your_freeplane_file.mm

cs 复制代码
应用系统名,用例编号,模块名,测试用例描述,正反向,执行步骤,预期结果
应用系统,模块1,功能11-测试要点111,正向,1.步骤,1.结果
应用系统,模块1,功能11-测试要点112,正向,2.步骤,2.结果
应用系统,模块1,功能11-要点111,反向,3.步骤,3.结果
应用系统,模块1,功能11-要点112,反向,4.步骤,4.结果
应用系统,模块2,功能21-测试要点211,正向,5.步骤,5.结果
应用系统,模块2,功能21-测试要点212,正向,6.步骤,6.结果
应用系统,模块2,功能21-要点211,反向,7.步骤,7.结果
应用系统,模块2,功能21-要点212,反向,8.步骤,8.结果
相关推荐
玩泥巴的1 天前
飞书 .NET SDK 事件处理的幂等性与去重机制
c#·.net·二次开发·飞书
在路上看风景1 天前
3.2 FileStream
c#
zwm2698888151 天前
6号楼 部分声光24v电压达不到,显示11v
c#
椒颜皮皮虾1 天前
TensorRtSharp:在 C# 世界中释放 GPU 推理的极致性能
c#·tensorrt
行止951 天前
WinForms 彻底隐藏 滚动条的终极解决方案
c#
bugcome_com1 天前
WPF样式进阶实战:外置样式+MVVM主题切换+样式优先级全解析
c#·.net·wpf
时光追逐者1 天前
TIOBE 公布 C# 是 2025 年度编程语言
开发语言·c#·.net·.net core·tiobe
观无1 天前
固高运动控制卡(GST800)基础应用分享
c#
flysh051 天前
如何利用 C# 内置的 Action 和 Func 委托
开发语言·c#
逑之1 天前
C语言笔记1:C语言常见概念
c语言·笔记·c#