Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/333.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何读取XmlDiff.Compare()生成的diffgram文件_C#_Testcomplete_Xmldiff - Fatal编程技术网

C# 如何读取XmlDiff.Compare()生成的diffgram文件

C# 如何读取XmlDiff.Compare()生成的diffgram文件,c#,testcomplete,xmldiff,C#,Testcomplete,Xmldiff,我正在使用XMLDiff.compare()比较两个XML文件,这是我第一次使用它,但我无法弄清楚如何处理生成的diffgram文件,以便为两个XML中的差异生成HTML bool bIdentical = xmldiff.Compare(originalFile, newFile, false, diffgramWriter); 原始文件在哪里 <?xml version="1.0" encoding="utf-8"?> <testsOutputData> <T

我正在使用XMLDiff.compare()比较两个XML文件,这是我第一次使用它,但我无法弄清楚如何处理生成的diffgram文件,以便为两个XML中的差异生成HTML

bool bIdentical = xmldiff.Compare(originalFile, newFile, false, diffgramWriter);
原始文件在哪里

<?xml version="1.0" encoding="utf-8"?>
<testsOutputData>
<TestName_AK1>
    <FeatureID ID="33B50792-207E514">
        <Intance_ID_1 >
            <CommandString>ABC </CommandString>
            <ProductID>100000</ProductID>
            <ProjectName>No Project</ProjectName>
            <TaskID>TESTSUITE</TaskID>
            <Type>Local</Type>
            <User></User>
        </Intance_ID_1>
        <Intance_ID_2>
            <CommandString>PQR </CommandString>
            <ProductID>1000</ProductID>
            <ProjectName>No Project</ProjectName>
            <TaskID>TESTSUITE</TaskID>
            <Type>Local</Type>
            <User></User>
        </Intance_ID_2>
        <Intance_ID_3>
            <CommandString>ABC </CommandString>
            <ProductID>1000</ProductID>
            <ProjectName>No Project</ProjectName>
            <TaskID>TESTSUITE</TaskID>
            <Type>Local</Type>
            <User></User>
        </Intance_ID_3>
    </FeatureID>
</TestName_AK1>

基础知识
100000
没有项目
测试套件
地方的
PQR
1000
没有项目
测试套件
地方的
基础知识
1000
没有项目
测试套件
地方的

新文件是

<?xml version="1.0" encoding="utf-8"?>
<testsOutputData>
<TestName_AK1>
    <FeatureID ID="33B50792-207E514">
        <Intance_ID_2>
            <CommandString>PQR </CommandString>
            <ProductID>1000</ProductID>
            <ProjectName>No Project</ProjectName>
            <TaskID>TESTSUITE</TaskID>
            <Type>Local</Type>
            <User></User>
        </Intance_ID_2>
        <Intance_ID_1 >
            <CommandString>ABC </CommandString>
            <ProductID>100000</ProductID>
            <ProjectName>No Project</ProjectName>
            <TaskID>TESTSUITE</TaskID>
            <Type>Local</Type>
            <User></User>
        </Intance_ID_1>
        <Intance_ID_3>
            <CommandString>ABC </CommandString>
            <ProductID>1000</ProductID>
            <ProjectName>No Project</ProjectName>
            <TaskID>TESTSUITE</TaskID>
            <Type>Local</Type>
            <User></User>
        </Intance_ID_3>
    </FeatureID>
</TestName_AK1>

PQR
1000
没有项目
测试套件
地方的
基础知识
100000
没有项目
测试套件
地方的
基础知识
1000
没有项目
测试套件
地方的

生成的diffgramwriter为

<xd:xmldiff version="1.0" srcDocHash="11314582626391529293" options="None" fragments="no" xmlns:xd="http://schemas.microsoft.com/xmltools/2002/xmldiff">
<xd:node match="2">
<xd:node match="1">
  <xd:node match="1">
    <xd:add match="/2/1/1/2" opid="1" />
    <xd:remove match="2" opid="1" />
  </xd:node>
</xd:node>
</xd:node>
<xd:descriptor opid="1" type="move" />
</xd:xmldiff>

现在使用这个需要生成HTML文件。(这是后面的部分) 但我无法正确理解(读取)diffgram文件, 无法理解

<xd:add match="/2/1/1/2" opid="1" />
    <xd:remove match="2" opid="1" />


在其他情况下,它们在其他diffgram中更多地是这种类型的节点。
我如何理解这个diffgram文件,以便生成一个HTML文件,您可以在XmlDiffView类中使用diffgram。但对我来说,它并不完美。它突出显示了差异,但也显示了我删除了一些节点并添加了新节点

XmlDiffView dv = new XmlDiffView();
//Load the original file again and the diff file.
XmlTextReader orig = new XmlTextReader("F:\\XML_1.xml");
        XmlTextReader diffGram = new XmlTextReader("F:\\diff.xml");
        dv.Load(orig,
            diffGram);

        //Wrap the HTML file with necessary html and 
        //body tags and prepare it before passing it to the GetHtml method.

        string tempFile =  "F:\\diff" +r.Next() + ".htm";
        StreamWriter sw1 = new StreamWriter(tempFile);
        sw1.Write("<html><body><table width='100%'>");
        //Write Legend.
        sw1.Write("<tr><td colspan='2' align='center'><b>Legend:</b> <font style='background-color: yellow'" +
            " color='black'>added</font>&nbsp;&nbsp;<font style='background-color: red'" +
            " color='black'>removed</font>&nbsp;&nbsp;<font style='background-color: " +
            "lightgreen' color='black'>changed</font>&nbsp;&nbsp;" +
            "<font style='background-color: red' color='blue'>moved from</font>" +
            "&nbsp;&nbsp;<font style='background-color: yellow' color='blue'>moved to" +
            "</font>&nbsp;&nbsp;<font style='background-color: white' color='#AAAAAA'>" +
            "ignored</font></td></tr>");

        dv.GetHtml(sw1);
        sw1.Write("</table></body></html>");
        sw1.Close();
        dv = null;
        orig.Close();
        diffGram.Close();
XmlDiffView dv=新的XmlDiffView();
//再次加载原始文件和差异文件。
XmlTextReader orig=新的XmlTextReader(“F:\\XML\u 1.XML”);
XmlTextReader diffGram=新的XmlTextReader(“F:\\diff.xml”);
dv.荷载(原始,
扩散图);
//用必要的HTML和
//body标记,并在将其传递给GetHtml方法之前进行准备。
字符串tempFile=“F:\\diff”+r.Next()+”.htm”;
StreamWriter sw1=新的StreamWriter(临时文件);
sw1.写(“”);
//写传奇。
sw1.写入(“图例:添加-删除-更改”+
“从”+
“移动到”+
"  " +
“忽略”);
dv.GetHtml(sw1);
sw1.写(“”);
sw1.Close();
dv=null;
原始关闭();
diffGram.Close();
我使用您的xml文件运行了这个程序,它们是相等的。当我将值CommandString从ABC修改为ABCD时,我得到了高亮度的更改值

XmlDiffView dv = new XmlDiffView();
//Load the original file again and the diff file.
XmlTextReader orig = new XmlTextReader("F:\\XML_1.xml");
        XmlTextReader diffGram = new XmlTextReader("F:\\diff.xml");
        dv.Load(orig,
            diffGram);

        //Wrap the HTML file with necessary html and 
        //body tags and prepare it before passing it to the GetHtml method.

        string tempFile =  "F:\\diff" +r.Next() + ".htm";
        StreamWriter sw1 = new StreamWriter(tempFile);
        sw1.Write("<html><body><table width='100%'>");
        //Write Legend.
        sw1.Write("<tr><td colspan='2' align='center'><b>Legend:</b> <font style='background-color: yellow'" +
            " color='black'>added</font>&nbsp;&nbsp;<font style='background-color: red'" +
            " color='black'>removed</font>&nbsp;&nbsp;<font style='background-color: " +
            "lightgreen' color='black'>changed</font>&nbsp;&nbsp;" +
            "<font style='background-color: red' color='blue'>moved from</font>" +
            "&nbsp;&nbsp;<font style='background-color: yellow' color='blue'>moved to" +
            "</font>&nbsp;&nbsp;<font style='background-color: white' color='#AAAAAA'>" +
            "ignored</font></td></tr>");

        dv.GetHtml(sw1);
        sw1.Write("</table></body></html>");
        sw1.Close();
        dv = null;
        orig.Close();
        diffGram.Close();