私は初めてXmlDiffPatchを使用しようとしていますが、どこにも高速にはいられません!XmlDiffPatchのヘルプ、ノード数でXML docをナビゲートしますか?
私がやりたいことは、2つのXMLファイルの情報セットを比較し、その違いとXPathをそのファイル内の変更に一覧表示することです。
多くのグーグルの後、私は次のコードを見つけたので、これまでと同じように動作します。比較して変更を見つけ、下のファイルを作成しますが、どのようにしてxpathsを取得しますか? 「XD::。私はちょうどこの発見した
<xd:node match="4"/>
:ノード要素が参照されるノードを特定するパス記述子でmatch属性が含まれてい
ここでは、この要素がどのように見えるかもしれないものの一例です
現在のソース要素の4番目のノードを識別するために使用されるxd:node要素の例です.4番目のノードの子ノードの変更は、xd:node要素の子ノードに記述されます。
<xd:node match="4">
<xd:change match="1">Changed text</change>
<xd:remove match="2" />
</xd:node>
ノードの数を数えることでXML文書をどのように動かすことができますか?
出力ファイルvxd.out:これまで
<?xml version="1.0" encoding="utf-8"?>
<xd:xmldiff version="1.0" srcDocHash="4711104825377024894" options="None" fragments="no" xmlns:xd="http://schemas.microsoft.com/xmltools/2002/xmldiff">
<xd:node match="2">
<xd:node match="1">
<xd:node match="2">
<xd:node match="4">
<xd:change match="1">TESTING</xd:change>
</xd:node>
</xd:node>
<xd:node match="4">
<xd:node match="5">
<xd:change match="1">A1</xd:change>
</xd:node>
</xd:node>
</xd:node>
</xd:node>
</xd:xmldiff>
コード:
public void DoCompare(string file1, string file2)
{
Random r = new Random();
string startupPath = Application.StartupPath;
//output diff file.
diffFile = startupPath + Path.DirectorySeparatorChar + "vxd.out";
XmlTextWriter tw = new XmlTextWriter(new StreamWriter(diffFile));
tw.Formatting = Formatting.Indented;
bool isEqual = false;
//Now compare the two files.
try
{
isEqual = diff.Compare(file1, file2, compareFragments, tw);
}
catch (XmlException xe)
{
MessageBox.Show("An exception occured while comparing\n" + xe.StackTrace);
}
finally
{
tw.Close();
}
if (isEqual)
{
//This means the files were identical for given options.
MessageBox.Show("Files Identical for the given options");
return; //dont need to show the differences.
}
//Files were not equal, so construct XmlDiffView.
XmlDiffView dv = new XmlDiffView();
//Load the original file again and the diff file.
XmlTextReader orig = new XmlTextReader(file1);
XmlTextReader diffGram = new XmlTextReader(diffFile);
dv.Load(orig, diffGram);
}