Friday, August 30, 2013

I have two XML documents, identical in structure. If a element value in A is different than B, then it needs to be copied to B (or a copy of B).

If the size and the structure of the files is identical, you could perhaps the files process one string line at a time instead of using XElement or XMLDocument classes. But, I suppose this will only succeed with rather simple XML files:



string pattern = @">.+\s?.*</";
//path = <your A.xml file>
//destPath = <your B.xml file>
string[] source = File.ReadAllLines(path);
string[] dest = File.ReadAllLines(destPath);
Regex regex = new Regex(pattern);

for (int i = 0; i < source.Length; i++) {
if (regex.IsMatch(source[i])) {
Match match = regex.Match(source[i]);
if (!match.Value.Contains("No Change")) {
dest[i] = Regex.Replace(dest[i], pattern, match.Value);
}
}
}
File.WriteAllLines(destPath, dest);

Kind regards,


wizend


No comments:

Post a Comment