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.结果
相关推荐
Accpdaiyekun2 小时前
C# 操作mongodb 多次查询快还是使用管道查询速度快
mongodb·c#·lua
Dm_dotnet2 小时前
C#:wpf ui 4.0 是如何实现页面导航的?
c#
圆滚滚肉肉4 小时前
后端MVC(控制器与动作方法的关系)
后端·c#·asp.net·mvc
ajassi20004 小时前
开源 C# .net mvc 开发(六)发送邮件、定时以及CMD编程
linux·开源·c#·mvc
我是唐青枫4 小时前
C#.NET NLog 详解
开发语言·c#·.net
向宇it5 小时前
【unity游戏开发——网络】网络游戏通信方案——强联网游戏(Socket长连接)、 弱联网游戏(HTTP短连接)
网络·http·游戏·unity·c#·编辑器·游戏引擎
一线码农6 小时前
MinHook 如何对 .NET 母体 CoreCLR 进行拦截
c#·.net·代码注入
小老鼠爱大米9 小时前
[C#] WPF - 资源URI
c#·wpf·uri
李少兄10 天前
解决OSS存储桶未创建导致的XML错误
xml·开发语言·python
阿蒙Amon10 天前
《C#图解教程 第5版》深度推荐
开发语言·c#