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.结果
相关推荐
我才是银古6 小时前
当 GIS 开发遇上 .NET:一个 GDAL 集成工具库的架构设计与实践
c#·gis·gdal
Hesionberger6 小时前
快速求解完全平方数的最少数量
开发语言·数据结构·python·算法·leetcode·c#
逝水无殇19 小时前
C# 运算符重载详解
开发语言·后端·c#
丁小未1 天前
基于MVVM框架的XUUI HelloWorld 新手教程
unity·性能优化·c#·游戏引擎
ctrl_v助手1 天前
C#日志工具类log4net的使用
开发语言·c#
Jazz_z1 天前
通过 Java 实现 Word 转 TXT
java·c#·word
丁小未1 天前
基于MVVM框架的XUUI MoreComplex案例
unity·c#
ctrl_v助手1 天前
C#表达题笔记
开发语言·c#
斯特凡今天也很帅1 天前
xml页面可以打开,不报错,但是显示数据的地方也不显示,我是怎么解决的
xml·vue.js
geovindu1 天前
CSharp: Dijkstra Algorithms
开发语言·后端·算法·c#