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.结果
相关推荐
我好喜欢你~7 小时前
C#---StopWatch类
开发语言·c#
阿华的代码王国10 小时前
【Android】RecyclerView复用CheckBox的异常状态
android·xml·java·前端·后端
一阵没来由的风10 小时前
拒绝造轮子(C#篇)ZLG CAN卡驱动封装应用
c#·can·封装·zlg·基础封装·轮子
一枚小小程序员哈17 小时前
基于微信小程序的家教服务平台的设计与实现/基于asp.net/c#的家教服务平台/基于asp.net/c#的家教管理系统
后端·c#·asp.net
Eternity_GQM18 小时前
【Word VBA Zotero 引用宏错误分析与改正指南】【解决[21–23]参考文献格式插入超链接问题】
开发语言·c#·word
cimeo1 天前
【C 学习】06-算法&程序设计举例
c#
百锦再1 天前
.NET 的 WebApi 项目必要可配置项都有哪些?
java·开发语言·c#·.net·core·net
WYH2871 天前
C#控制台输入(Read()、ReadKey()和ReadLine())
开发语言·c#
hqwest1 天前
C#WPF实战出真汁06--【系统设置】--餐桌类型设置
c#·.net·wpf·布局·分页·命令·viewmodel
做一位快乐的码农2 天前
基于.net、C#、asp.net、vs的保护大自然网站的设计与实现
c#·asp.net·.net