Xml Comparison in C# -
I am trying to compare two XML files using the C # code. I want to ignore the XML syntax (i.e. prefix name) for this, I am using Microsoft's C # API. It works for some XML, but I could not find any way to configure it to work with the following two XML:
XML A:
& Lt; Root xmlns: ns = "http: // myNs" & gt; & Lt; Ns: children & gt; 1 & lt; / Ns: children & gt; & Lt; / Root & gt; XML B:
& lt; Root & gt; & Lt; Child xmlns = "http: // myNs" & gt; 1 & lt; / Child & gt; & Lt; / Root & gt; My questions are:
- Am I right that these two XML are semantically (or areomorphic)?
- Can Microsoft's XML Diff and Patch API be configured to support it?
- Is there any other C # utility in it?
Documents are isomorphic as can be shown by the program below. I think if you use XmlDiffOptions.IgnoreNamespaces and XmlDiffOptions.IgnorePrefixes to configure Microsoft.XmlDiffPatch.XmlDiff , then You get the result you want.
using System.Linq; Using System.Xml.Linq; Namespace SO_794331 {class program {static zero main (string [] args) {var docA = XDocument.Parse (@ "& lt; root xmlns: ns =" "http: // myNs" "& gt; & lt; Ns: child> 1 & lt; / ns: child & gt; & lt; / root & gt; "); Var docB = XDocument.Parse (@ "& lt; Route & gt; Child xmlns =" "http: // myNs" "& gt; 1 & lt; / root & Gt; "); Var rootNameA = docA.Root.Name; Var rootNameB = docB.Root.Name; Var equalRootNames = rootNameB.Equals (rootNameA); Wind descendantsA = docA.Root.Descendants (); Var descendants B = docB.Root.Descendants (); For (int i = 0; i
Comments
Post a Comment