This raises a difficult question.
I have one MainFile.XML file that looks like this:
<xml>
<header>
<some></some>
<addThis></addThis>
</header>
<footer></footer>
<this>
<is>
<deep>
<like></like>
</deep>
</is>
</this>
<test></test>
<page></page>
<addThis></addThis>
And my other LangFile.XML file looks like this.
<xml>
<header>
<some>English file</some>
</header>
<footer>Footer</footer>
<this>
<is>
<deep>
<like>Hey</like>
</deep>
</is>
</this>
<test>Something</test>
</xml>
I want to update my LangFile.XML so that it matches my MainFile.XML file, but I need to save all the Text values in the LangFile.
I want the LangFile to look like this after the update:
EXPECTED EXIT
<xml>
<header>
<some>English file</some>
<addThis></addThis>
</header>
<footer>Footer</footer>
<this>
<is>
<deep>
<like>Hey</like>
</deep>
</is>
</this>
<test>Something</test>
<page></page>
<addThis></addThis>
</xml>
I looked at this answer, but I need to update the file and save the values ...
Comparing two text files line by line
The hard part is investing, it can be anything between levels from level 1 to X ...
, , , , - , ... , .
String directory = @"C:\Utv\XmlTest";
var mainFile = XDocument.Load(Path.Combine(directory, "MainFile.XML"));
var langFile = XDocument.Load(Path.Combine(directory, "LangFile.XML"));
var mainFileDesc = mainFile.Root.Descendants().ToList();
var langFileDesc = langFile.Root.Descendants().ToList();
for(var i = 0; i < mainFileDesc.Count(); i++)
{
var mainRow = mainFileDesc[i];
var langRow = langFileDesc[i];
if(mainRow.Descendants().Count() != langRow.Descendants().Count())
{
if(mainRow != langRow)
{
langFileDesc.Insert(i, mainRow);
}
}
}
:
var langRow = langFileDesc[i];
Message Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index
, , ...