I have a complicated case: I have three XML files, which I need to read simultaneously and get the results based on matches. Below is a working (but fake) example, almost similar to what I am doing.
For instance, I have two xml file, both are similar but in terms of tags and attributes, but with different contents (languages). I’m reading both languages at the same time, like in the code in a C# file:
XElement x1 = XElement.Load (@"abc.xml");
XElement x2 = XElement.Load (@"xyz.xml");
var ch = from var1 in x1.Elements("language1")
where var1.Attribute("index").Value == "1"
from var2 in x2.Elements("language2")
where var2.Attribute("index").Value == var1.Attribute("index").Value
select dictChapter as new
{
sentenceNumber = var1.Attribute("index").Value,
SentenceInLanguage1 = var1.Attribute("text").Value,
SentenceInLanguage2 = var2.Attribute("text").Value,
};
ListBox.DataContext = ch;
The problem here is that, x1 contains 1000 sentences and so x2. The above logic work like a nested loop, which is slowing down the processing a lot. It works like
x1.1 -> x2.1:1000
x1.2 -> x2.1:1000
or
for i in x1
for j in x2
Is there any better and efficient way to select the sentences from x1 and x2,where the sentence id of x1 is equal to the sentence id of x2?
From what I understood that you want,
You could use
jointo do that.Here is a good example link LINQ to XML : Join Xml Data (Wriju’s BLOG)
…or something along these lines…