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.结果
相关推荐
枯萎穿心攻击3 小时前
ECS由浅入深第三节:进阶?System 的行为与复杂交互模式
开发语言·unity·c#·游戏引擎
小码编匠3 小时前
WPF 自定义TextBox带水印控件,可设置圆角
后端·c#·.net
水果里面有苹果3 小时前
17-C#的socket通信TCP-1
开发语言·tcp/ip·c#
旷世奇才李先生4 小时前
XML DOM 安装使用教程
xml·前端·chrome
阿蒙Amon11 小时前
C# Linq to SQL:数据库编程的解决方案
数据库·c#·linq
iCxhust14 小时前
c# U盘映像生成工具
开发语言·单片机·c#
emplace_back15 小时前
C# 集合表达式和展开运算符 (..) 详解
开发语言·windows·c#
阿蒙Amon16 小时前
为什么 12 版仍封神?《C# 高级编程》:从.NET 5 到实战架构,进阶者绕不开的必修课
开发语言·c#
深海潜水员17 小时前
【Behavior Tree】-- 行为树AI逻辑实现- Unity 游戏引擎实现
游戏·unity·c#